May-19-2018, 09:09 PM
I'm reading Automate boring stuff with Python and the given example of creating a file when it's not already there is this one:
But I receive an error
baconFile = open('C:\\Python36\\kodovi\\bacon.txt', 'w') baconFile.write('Hello world!\n') baconFile.close() baconFile = open('C:\\Python36\\kodovi\\bacon.txt', 'a') baconFile.write('Bacon is not a vegetable.') baconFile.close() baconFile = open('C:\\Python36\\kodovi\\bacon.text') content = baconFile.read() baconFile.close print(content)the book says that "since there isn’t a bacon.txt yet, Python creates one."
But I receive an error
Error:FileNotFoundError: [Errno 2] No such file of directory: 'C:\\Python36\\kodovi\\bacon.txt'
I'm pretty sure that there is such directory as I used it for some previous code and it worked fine. This means that Python is telling me that files cannot be created this way. Was author wrong ( which is hard for me to believe )?