Python direct path file printing issue? -


so have script needs print file in different directory. give absolute path , python doesn't it.

here's file located: c:\users\owner\documents\senior_design\qt_library\build-transmitterplot-desktop_qt_5_0_2_msvc2010_32bit-debug\numbers.txt

(i know, long path, qt plotter makes file names long)

i typed:

textfile = open('c:\users\owner\documents\senior_design\qt_library\build-transmitterplot-desktop_qt_5_0_2_msvc2010_32bit-debug\numbers.txt', 'w') 

and error:

ioerror: [errno 22] invalid mode ('w') or filename: 

i've read can use relative paths, unsure how give relative path many directories go through.

thanks!

the problem python interpreting backslashes in path escape sequences:

>>> 'c:\users\owner\documents\senior_design\qt_library\build-transmitterplot-desktop_qt_5_0_2_msvc2010_32bit-debug\numbers.txt' 'c:\\users\\owner\\documents\\senior_design\\qt_library\x08uild-transmitterplot-desktop_qt_5_0_2_msvc2010_32bit-debug\numbers.txt' 

notice both \b , \n translated else. use "raw" string instead:

>>> r'c:\users\owner\documents\senior_design\qt_library\build-transmitterplot-desktop_qt_5_0_2_msvc2010_32bit-debug\numbers.txt' 'c:\\users\\owner\\documents\\senior_design\\qt_library\\build-transmitterplot-desktop_qt_5_0_2_msvc2010_32bit-debug\\numbers.txt' 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -