Saving Files In New Directory (python) -
i'm trying take input file , save new folder on computer, can't figure out how correctly.
here code tried:
from os.path import join pjoin = raw_input("file name: ") filepath = "c:\documents , settings\user\my documents\'a'" fout = open(filepath, "w") path_to_file = pjoin("c:\documents , settings user\my documents\dropbox",'a') file = open(path_to_file, "w")
when run it, it's putting 2 \
in between each sub-directory instead of 1 , it's telling me it's not existing file or directory.
i sure there easier way this, please help.
why have unescaped "'quotes_like_this_inside_quotes'"
? may reason failure.
from can understand, directories saving "c:\documents , settings\user\my documents\'
, 'c:\documents , settings\user\my documents\'
.
whenever messing directories/paths use os.expanduser('~/something/blah')
.
try this:
from os.path import expanduser, join path_to_file1 = join(expanduser('~/dropbox/'), 'a') path_to_file2 = join(expanduser('~'), 'a') fout = open(path_to_file2, "w") file = open(path_to_file1, "w")
and double-backslashes ok, afaik. let me know if works - i'm not on windows box @ moment.
Comments
Post a Comment