os.path.isdir do not work for Foder named '2011-07-03'
steve+comp.lang.python at pearwood.info
Tue Jul 19 00:42:26 EDT 2011
> I want to make sure that folder exists.
> '2011-07-03' is really exists. but 'os.path.isdir' say false
> Does anyone know why?
>>> print "logs/2011-07-03"
>>> print "logs\2011-07-03"
Don't use backslashes as path separators in Python. Backslashes are used for
\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"
(2) Use forward slashes, as Windows will happily accept them instead of
(3) Use another operating system. *wink*
More information about the Python-list