Re: [Tutor] Need help with FileNotFoundError

2018-04-26 Thread Jim

On 04/26/2018 03:27 PM, Danny Yoo wrote:

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



Hi Jim,

You may need to use os.path.expanduser, as "tilde expansion" isn't
something that's done automatically.

This is referenced in the docs when they say: "Unlike a unix shell, Python
does not do any automatic path expansions. Functions such as expanduser()
and expandvars() can be invoked explicitly when an application desires
shell-like path expansion. (See also the glob module.)"

  https://docs.python.org/3/library/os.path.html#module-os.path

Try adding a call to os.path.expanduser()
https://docs.python.org/3/library/os.path.html#os.path.expanduser on that
tilde-prefixed path string.

Hope this helps!


Danny,

Thanks for pointing me in the right direction. I had tried replacing the 
~ with home/jfb/... now I realize it should have been /home/jfb/... 
Working now.


Thanks,  Jim


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Need help with FileNotFoundError

2018-04-26 Thread Danny Yoo
> copy('~/Documents/Courses/ModernBootcamp/story.txt',
> '~/Documents/Courses/ModernBootcamp/story_copy.txt')


Hi Jim,

You may need to use os.path.expanduser, as "tilde expansion" isn't
something that's done automatically.

This is referenced in the docs when they say: "Unlike a unix shell, Python
does not do any automatic path expansions. Functions such as expanduser()
and expandvars() can be invoked explicitly when an application desires
shell-like path expansion. (See also the glob module.)"

 https://docs.python.org/3/library/os.path.html#module-os.path

Try adding a call to os.path.expanduser()
https://docs.python.org/3/library/os.path.html#os.path.expanduser on that
tilde-prefixed path string.

Hope this helps!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Need help with FileNotFoundError

2018-04-26 Thread Jim
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@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 
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@jims-mint18 ~/Documents/Courses/ModernBootcamp $ ls
adding_to_lists.py  errors.py functionsII.pyhelpers.py 
modules.py   stop_copying.py
animals exercise.py   functions.py  iteration.py 
oop.py   story.txt
decorators.py   file_io.pygenerators.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
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor