[Tutor] Need help with FileNotFoundError

Jim jf_byrnes at comcast.net
Thu Apr 26 16:18:39 EDT 2018


Been working my way through an online Python course. Up until now I have 
had no problems writing and running the programs using Python 3.6 in a 
virtual environment and then pasting them into the courses editor.

When I run this program on my system I get the following error.


# file_io.py

def copy(file, new_file):
     with open(file) as data:
         text = data.read()


     with open(new_file, 'w') as new_text:
         new_text.write(text)

copy('~/Documents/Courses/ModernBootcamp/story.txt', 
'~/Documents/Courses/ModernBootcamp/story_copy.txt')


(env36) jfb at jims-mint18 ~ $ python 
'/home/jfb/Documents/Courses/ModernBootcamp/file_io.py'
Traceback (most recent call last):
   File "/home/jfb/Documents/Courses/ModernBootcamp/file_io.py", line 
11, in <module>
     copy('~/Documents/Courses/ModernBootcamp/story.txt', 
'~/Documents/Courses/ModernBootcamp/story_copy.txt')
   File "/home/jfb/Documents/Courses/ModernBootcamp/file_io.py", line 4, 
in copy
     with open(file) as data:
FileNotFoundError: [Errno 2] No such file or directory: 
'~/Documents/Courses/ModernBootcamp/story.txt'

The file is there.

jfb at jims-mint18 ~/Documents/Courses/ModernBootcamp $ ls
adding_to_lists.py  errors.py     functionsII.py    helpers.py 
modules.py       stop_copying.py
animals             exercise.py   functions.py      iteration.py 
oop.py           story.txt
decorators.py       file_io.py    generators.py     list_comps.py 
__pycache__      unlucky_numbers.py
dictionarys.py      FirstProgram  guessing_game.py  list_methods.py 
smiley_faces.py  while_loop.py

I must be doing something wrong path-wise, but I can't seem to figure it 
out. Any help appreciated.

Regards,  Jim


More information about the Tutor mailing list