Reading/Writing files
Ethan Furman
ethan at stoneleaf.us
Fri Mar 18 19:00:55 EDT 2011
Dan Stromberg wrote:
>
> Are you on windows?
>
> You probably should use / as your directory separator in Python, not \.
> In Python, and most other programming languages, \ starts an escape
> sequence, so to introduce a literal \, you either need to prefix your
> string with r (r"\foo\bar") or double your backslashes ("\\foo\\bar").
>
> / works fine on windows, and doesn't require escaping ("/foo/bar").
Depends on your definition of 'fine'.
--> from glob import glob
--> from pprint import pprint as pp
--> pp(glob('c:/temp/*.pdf'))
['c:/temp\\choose_python.pdf',
'c:/temp\\COA.pdf',
'c:/temp\\job_setup.pdf']
Visually ugly, and a pain to compare files and paths.
~Ethan~
More information about the Python-list
mailing list