Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #9847 > unrolled thread
| Started by | Nulpum <changjun.cho@gmail.com> |
|---|---|
| First post | 2011-07-18 21:25 -0700 |
| Last post | 2011-07-19 14:21 +0000 |
| Articles | 13 — 11 participants |
Back to article view | Back to comp.lang.python
os.path.isdir do not work for Foder named '2011-07-03' Nulpum <changjun.cho@gmail.com> - 2011-07-18 21:25 -0700
Re: os.path.isdir do not work for Foder named '2011-07-03' Kushal Das <kushaldas@gmail.com> - 2011-07-19 10:11 +0530
Re: os.path.isdir do not work for Foder named '2011-07-03' Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-07-19 14:42 +1000
Re: os.path.isdir do not work for Foder named '2011-07-03' Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-07-19 08:15 +0200
Re: os.path.isdir do not work for Foder named '2011-07-03' Changjun <changjun.cho@gmail.com> - 2011-07-19 01:25 -0700
Re: os.path.isdir do not work for Foder named '2011-07-03' Terry Reedy <tjreedy@udel.edu> - 2011-07-19 13:51 -0400
Re: os.path.isdir do not work for Foder named '2011-07-03' Thomas Jollans <t@jollybox.de> - 2011-07-19 08:30 +0200
Re: os.path.isdir do not work for Foder named '2011-07-03' Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-07-19 17:26 +1000
Re: os.path.isdir do not work for Foder named '2011-07-03' Ethan Furman <ethan@stoneleaf.us> - 2011-07-19 07:22 -0700
Re: os.path.isdir do not work for Foder named '2011-07-03' Nulpum <changjun.cho@gmail.com> - 2011-07-19 00:21 -0700
Re: os.path.isdir do not work for Foder named '2011-07-03' Michael Hrivnak <mhrivnak@hrivnak.org> - 2011-07-19 00:42 -0400
Re: os.path.isdir do not work for Foder named '2011-07-03' Rob Williscroft <rtw@rtw.me.uk> - 2011-07-19 04:56 +0000
Re: os.path.isdir do not work for Foder named '2011-07-03' Grant Edwards <invalid@invalid.invalid> - 2011-07-19 14:21 +0000
| From | Nulpum <changjun.cho@gmail.com> |
|---|---|
| Date | 2011-07-18 21:25 -0700 |
| Subject | os.path.isdir do not work for Foder named '2011-07-03' |
| Message-ID | <0bf400a3-735c-487a-8d74-feb3b56be99b@g5g2000prn.googlegroups.com> |
I want to make sure that folder exists.
'2011-07-03' is really exists. but 'os.path.isdir' say false
Does anyone know why?
>>> os.path.isdir("C:\Users\조창준\Desktop\logs")
True
>>> os.path.isdir("C:\Users\조창준\Desktop\logs\2011-07-03")
False
[toc] | [next] | [standalone]
| From | Kushal Das <kushaldas@gmail.com> |
|---|---|
| Date | 2011-07-19 10:11 +0530 |
| Message-ID | <mailman.1235.1311050497.1164.python-list@python.org> |
| In reply to | #9847 |
2011/7/19 Nulpum <changjun.cho@gmail.com>:
> I want to make sure that folder exists.
>
> '2011-07-03' is really exists. but 'os.path.isdir' say false
>
> Does anyone know why?
>
>
>
>>>> os.path.isdir("C:\Users\조창준\Desktop\logs")
> True
>>>> os.path.isdir("C:\Users\조창준\Desktop\logs\2011-07-03")
> False
Works here. Are you sure that it is not a file ?
>>> os.path.isdir('/tmp/2011-07-03')
True
Python 2.7.1 (r271:86832, Apr 12 2011, 16:15:16)
[GCC 4.6.0 20110331 (Red Hat 4.6.0-2)] on linux2
Kushal
--
http://fedoraproject.org
http://kushaldas.in
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2011-07-19 14:42 +1000 |
| Message-ID | <4e250b31$0$30001$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #9847 |
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
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2011-07-19 08:15 +0200 |
| Message-ID | <1704833.GPiq6Xz2PA@PointedEars.de> |
| In reply to | #9850 |
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. Besides that, and permission issues, ISTM that there are Unicode characters (at least non-ASCII characters) in the OP's path, which means they should declare # encoding: utf-8 or something else fitting, and use os.path.isdir(u"C:/Users/조창준/Desktop/logs/2011-07-03") or something else fitting. -- PointedEars Bitte keine Kopien per E-Mail. / Please do not Cc: me.
[toc] | [prev] | [next] | [standalone]
| From | Changjun <changjun.cho@gmail.com> |
|---|---|
| Date | 2011-07-19 01:25 -0700 |
| Message-ID | <807e1e1f-b616-4615-8655-f316f12f66df@a2g2000prf.googlegroups.com> |
| In reply to | #9857 |
On 7월19일, 오후3시15분, Thomas 'PointedEars' Lahn <PointedE...@web.de> wrote: > 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. > > Besides that, and permission issues, ISTM that there are Unicode characters > (at least non-ASCII characters) in the OP's path, which means they should > declare > > # encoding: utf-8 > > or something else fitting, and use > > os.path.isdir(u"C:/Users/조창준/Desktop/logs/2011-07-03") > > or something else fitting. > > -- > PointedEars > > Bitte keine Kopien per E-Mail. / Please do not Cc: me. Thanks... u Option is work :)
[toc] | [prev] | [next] | [standalone]
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Date | 2011-07-19 13:51 -0400 |
| Message-ID | <mailman.1265.1311098111.1164.python-list@python.org> |
| In reply to | #9857 |
On 7/19/2011 2:15 AM, Thomas 'PointedEars' Lahn wrote: > 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. > > Besides that, and permission issues, ISTM that there are Unicode characters > (at least non-ASCII characters) in the OP's path, which means they should > declare > > # encoding: utf-8 That is the default in Py3. Not sure of OP specified what he used. > > or something else fitting, and use > > os.path.isdir(u"C:/Users/조창준/Desktop/logs/2011-07-03") > -- Terry Jan Reedy
[toc] | [prev] | [next] | [standalone]
| From | Thomas Jollans <t@jollybox.de> |
|---|---|
| Date | 2011-07-19 08:30 +0200 |
| Message-ID | <mailman.1240.1311057034.1164.python-list@python.org> |
| In reply to | #9850 |
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
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2011-07-19 17:26 +1000 |
| Message-ID | <4e2531c1$0$29971$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #9859 |
Thomas Jollans wrote:
> On 19/07/11 06:42, Steven D'Aprano wrote:
>> (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'
Well, perhaps, but not all paths can be written as a raw string:
>>> path = r'a\b\c\'
File "<stdin>", line 1
path = r'a\b\c\'
^
SyntaxError: EOL while scanning single-quoted string
>> (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?)
Yes, but only just. Python still includes support for VMS, at least for now;
support is scheduled to be dropped in 3.3 and code supporting it to be
removed in 3.4.
--
Steven
[toc] | [prev] | [next] | [standalone]
| From | Ethan Furman <ethan@stoneleaf.us> |
|---|---|
| Date | 2011-07-19 07:22 -0700 |
| Message-ID | <mailman.1254.1311085427.1164.python-list@python.org> |
| In reply to | #9862 |
Steven D'Aprano wrote: > Thomas Jollans wrote: >> 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?) > > Yes, but only just. Python still includes support for VMS, at least for now; > support is scheduled to be dropped in 3.3 and code supporting it to be > removed in 3.4. Perhaps I misremember, but I thought somebody had stepped forward to keep OpenVMS support going? ... Ah, here it is -- Sandeep Mathew, in thread 'Python Support on OpenVMS' on python-dev. ~Ethan~
[toc] | [prev] | [next] | [standalone]
| From | Nulpum <changjun.cho@gmail.com> |
|---|---|
| Date | 2011-07-19 00:21 -0700 |
| Message-ID | <b954e128-27f1-49f4-ae8c-6a37a11334fc@z7g2000prh.googlegroups.com> |
| In reply to | #9850 |
On Jul 19, 1:42 pm, Steven D'Aprano <steve +comp.lang.pyt...@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.
[toc] | [prev] | [next] | [standalone]
| From | Michael Hrivnak <mhrivnak@hrivnak.org> |
|---|---|
| Date | 2011-07-19 00:42 -0400 |
| Message-ID | <mailman.1236.1311050546.1164.python-list@python.org> |
| In reply to | #9847 |
What is the output of:
>>> os.path.exists("C:\Users\조창준\Desktop\logs\2011-07-03")
? One possible issue here is that for some reason os.path.isdir()
can't even access the directory either because of permissions,
misinterpretation of the path, or some other reason.
Michael
2011/7/19 Nulpum <changjun.cho@gmail.com>:
> I want to make sure that folder exists.
>
> '2011-07-03' is really exists. but 'os.path.isdir' say false
>
> Does anyone know why?
>
>
>
>>>> os.path.isdir("C:\Users\조창준\Desktop\logs")
> True
>>>> os.path.isdir("C:\Users\조창준\Desktop\logs\2011-07-03")
> False
> --
> http://mail.python.org/mailman/listinfo/python-list
>
[toc] | [prev] | [next] | [standalone]
| From | Rob Williscroft <rtw@rtw.me.uk> |
|---|---|
| Date | 2011-07-19 04:56 +0000 |
| Message-ID | <mailman.1237.1311051439.1164.python-list@python.org> |
| In reply to | #9847 |
Nulpum wrote in news:0bf400a3-735c-487a-8d74-
feb3b56be99b@g5g2000prn.googlegroups.com in gmane.comp.python.general:
> I want to make sure that folder exists.
> '2011-07-03' is really exists. but 'os.path.isdir' say false
> Does anyone know why?
>
>>>> os.path.isdir("C:\Users\조창준\Desktop\logs")
> True
>>>> os.path.isdir("C:\Users\조창준\Desktop\logs\2011-07-03")
> False
Maybe it isn't a directory, but a file, what does os.path.exists() return.
Also could it be a "Shortcut" in which case 2011-07-03.lnk will exist.
Also have you left "Hide extensions for known file types" switched on,
in which case it may really be "2011-07-03.zip" for example, a file
not a directory even though Windows explorer shows it as a directory.
--
Rob.
[toc] | [prev] | [next] | [standalone]
| From | Grant Edwards <invalid@invalid.invalid> |
|---|---|
| Date | 2011-07-19 14:21 +0000 |
| Message-ID | <j043sv$oae$1@reader1.panix.com> |
| In reply to | #9847 |
On 2011-07-19, Nulpum <changjun.cho@gmail.com> 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?
>
>
>
>>>> os.path.isdir("C:\Users\??????\Desktop\logs")
> True
>>>> os.path.isdir("C:\Users\??????\Desktop\logs\2011-07-03")
> False
You're not using backslashes corrrectly. Try assigning the path
names to a "variable" and printing them. I think you'll see what's
wrong.
I'd try using forward slashes if I were you.
--
Grant Edwards grant.b.edwards Yow! I'm definitely not
at in Omaha!
gmail.com
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web