Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'python.': 0.04; 'escape': 0.04; 'happily': 0.07; 'python': 0.08; '>>>>': 0.09; 'backslash': 0.09; 'wrote:': 0.15; '(does': 0.16; 'backslashes': 0.16; 'paths.': 0.16; 'received:192.168.1.40': 0.16; 'slashes': 0.16; 'subject:named': 0.16; 'exists.': 0.19; 'solution.': 0.19; 'subject:not': 0.21; 'header:In-Reply-To:1': 0.22; 'assume': 0.23; 'elegant': 0.23; 'string': 0.26; 'windows': 0.26; 'all,': 0.28; 'yes.': 0.30; 'print': 0.32; "skip:' 10": 0.32; 'cases': 0.32; 'does': 0.32; 'anyone': 0.33; 'to:addr:python-list': 0.34; 'instead': 0.34; 'header:User-Agent:1': 0.34; 'operating': 0.34; 'there': 0.34; 'folder': 0.35; 'skip:" 10': 0.36; 'but': 0.37; 'another': 0.38; 'received:192': 0.38; 'subject:: ': 0.38; 'steven': 0.38; 'received:192.168.1': 0.39; 'to:addr:python.org': 0.39; 'raw': 0.40; 'forward': 0.62; '(3)': 0.63; 'received:62': 0.67; 'dealing': 0.69; 'why?': 0.73; 'from:addr:t': 0.84; 'subject:skip:o 10': 0.84 Date: Tue, 19 Jul 2011 08:30:34 +0200 From: Thomas Jollans User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.18) Gecko/20110626 Iceowl/1.0b2 Icedove/3.1.11 MIME-Version: 1.0 To: python-list@python.org Subject: Re: os.path.isdir do not work for Foder named '2011-07-03' References: <0bf400a3-735c-487a-8d74-feb3b56be99b@g5g2000prn.googlegroups.com> <4e250b31$0$30001$c3e8da3$5496439d@news.astraweb.com> In-Reply-To: <4e250b31$0$30001$c3e8da3$5496439d@news.astraweb.com> X-Enigmail-Version: 1.1.2 OpenPGP: id=5C8691ED Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 43 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1311057034 news.xs4all.nl 23935 [2001:888:2000:d::a6]:54140 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:9859 On 19/07/11 06:42, Steven D'Aprano 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. > > [snip] > > There are three solutions: > > (1) Escape every backslash with an extra backslash: > >>>> print "logs\\2011-07-03" > logs\2011-07-03 There is a more elegant solution: use raw strings: r'c:\foo\bar' > (2) Use forward slashes, as Windows will happily accept them instead of > backslashes. The "correct" solution in many cases is to not assume any particular path separator at all, and use os.path.join when dealing with paths. This will work even on systems that do not accept forward slashes as path separators. (does Python still support any of those?) > (3) Use another operating system. *wink* This, of course, is the only truly tenable solution. Thomas