os.path.isdir do not work for Foder named '2011-07-03'

Nulpum changjun.cho at gmail.com
Tue Jul 19 09:21:01 CEST 2011


On Jul 19, 1:42 pm, Steven D'Aprano <steve
+comp.lang.pyt... at pearwood.info> wrote:
> Nulpum wrote:
> > I want to make sure that folder exists.
>
> > '2011-07-03' is really exists. but 'os.path.isdir' say false
>
> > Does anyone know why?
>
> Yes.
>
> >>> print "logs/2011-07-03"
> logs/2011-07-03
> >>> print "logs\2011-07-03"
>
> logs 1-07-03
>
> Don't use backslashes as path separators in Python. Backslashes are used for
> string escapes.
>
> \n means newline, not backslash n
>
> \t means tab, not backslash t
>
> and \201 means octal character 0201 (hex 'x81', decimal 129).
>
> There are three solutions:
>
> (1) Escape every backslash with an extra backslash:
>
> >>> print "logs\\2011-07-03"
>
> logs\2011-07-03
>
> (2) Use forward slashes, as Windows will happily accept them instead of
> backslashes.
>
> (3) Use another operating system. *wink*
>
> --
> Steven

Thank you very much, Steven
You're right.

Now. It's OK.

Thanks again.




More information about the Python-list mailing list