My instructor provided the following code, but it is not working on OS X when run from command line.
file_name = 'data/' + raw_input('Enter the name of your file: ') + '.txt'
fout = open(file_name, 'w')
Error message:
Traceback (most recent call last):
File "write_a_poem_to_file.py", line 12, in <module>
fout = open(file_name, 'w')
IOError: [Errno 2] No such file or directory: 'data/poem1.txt'
I have been writing Python since before I got to the class and having done a little research, it think you need to import the os module to create a directory.
Then you can specify that you want to create a file in that directory.
I believe you might also have to switch into that directory before accessing files.
I may be wrong, and I am wondering if I am missing another issue.
data/exist?openwon't create a folder.