io - python open() escape backslash -
i have path file containing $ signs, escaped \ open() can handle path. open turns \$ \\$ automatically. example:
open("/home/test/\$somedir\$/file.txt", "r") result in error message ioerror: [errno 2] no such file or directory: '/home/test/\\$somedir\\$/file.txt' can supress this. why open() that? can't find in docu of open, describes this.
open() doesn't that. it's python, escapes special characters when representing string:
>>> path = '\$' >>> path '\\$' >>> print path \$ in regular python string literal, \ has special meaning, escaped when echoing value, can pasted right python script or interpreter session recreate same value.
on linux or mac, not need escape $ value in filename; $ has no special meaning in regular python string, nor in linux or mac filenames:
>>> os.listdir('/tmp/$somedir$') ['test'] >>> open('/tmp/$somedir$/test') <open file '/tmp/$somedir$/test', mode 'r' @ 0x105579390>
Comments
Post a Comment