[Tutor] Need help with FileNotFoundError

Danny Yoo dyoo at hashcollision.org
Thu Apr 26 16:27:28 EDT 2018


> 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!


More information about the Tutor mailing list