Re: os.path.isfile

2017-02-12 Thread eryk sun
On Sun, Feb 12, 2017 at 4:29 AM, Chris Angelico wrote: > Registry subkeys aren't paths, and the other two cases are extremely > narrow. Convert slashes to backslashes ONLY in the cases where you > actually need to. \\?\ paths are required to exceed MAX_PATH (a paltry 260 characters) or to avoid q

Re: os.path.isfile

2017-02-12 Thread Steve D'Aprano
On Mon, 13 Feb 2017 11:43 am, Chris Angelico wrote: > On Mon, Feb 13, 2017 at 11:40 AM, Erik wrote: >> FWIW, if you'd have written the above as your first response I wouldn't >> have argued ;) You alluded to it, for sure ... :D > > Nothing wrong with respectfully arguing. It's one of the best wa

Re: os.path.isfile

2017-02-12 Thread Chris Angelico
On Mon, Feb 13, 2017 at 11:40 AM, Erik wrote: > FWIW, if you'd have written the above as your first response I wouldn't have > argued ;) You alluded to it, for sure ... :D Nothing wrong with respectfully arguing. It's one of the best ways to zero in on the truth :) ChrisA -- https://mail.python

Re: os.path.isfile

2017-02-12 Thread Erik
On 13/02/17 00:34, Chris Angelico wrote: The unit "\t" always means U+0009, even if it's following a raw string literal; and the unit "\d" always means "\\d", regardless of the rawness of any of the literals involved. The thing that's biting you here is that unrecognized escapes get rendered as b

Re: os.path.isfile

2017-02-12 Thread Chris Angelico
On Mon, Feb 13, 2017 at 11:34 AM, Erik wrote: > OK, I get it now - because '\d' is not a valid escape sequence, then even in > a non-raw string literal, the '\' is treated as a literal backslash > character (not an escape). > > So, the second string token is NOT being treated as "raw", it just loo

Re: os.path.isfile

2017-02-12 Thread Erik
On 13/02/17 00:23, Erik wrote: r"hello \the" "worl\d" "\t" 'hello \\theworl\\d\t' The initial string is raw. The following string adopts that (same as the second example), but the _next_ string does not! Why is the first string token parsed as a "raw" string, the second string token also pars

Re: os.path.isfile

2017-02-12 Thread Chris Angelico
On Mon, Feb 13, 2017 at 11:29 AM, Erik wrote: > On 13/02/17 00:13, Chris Angelico wrote: >> >> On Mon, Feb 13, 2017 at 11:11 AM, Chris Angelico wrote: >>> >>> The string "\t" gets shown in the repr as "\t". It is a string >>> consisting of one character, U+0009, a tab. The string r"\t" is shown >

Re: os.path.isfile

2017-02-12 Thread Erik
On 13/02/17 00:13, Chris Angelico wrote: On Mon, Feb 13, 2017 at 11:11 AM, Chris Angelico wrote: The string "\t" gets shown in the repr as "\t". It is a string consisting of one character, U+0009, a tab. The string r"\t" is shown as "\\t" and consists of two characters, REVERSE SOLIDUS and LATI

Re: os.path.isfile

2017-02-12 Thread Erik
On 13/02/17 00:11, Chris Angelico wrote: Firstly, be aware that there's no such thing as a "raw string" - what you have is a "raw string literal". It's a purely syntactic feature. I do understand that. When I said "is raw"/"rawness", I am talking about what the _parser_ is doing. I don't think

Re: os.path.isfile

2017-02-12 Thread Chris Angelico
On Mon, Feb 13, 2017 at 11:11 AM, Chris Angelico wrote: > The string "\t" gets shown in the repr as "\t". It is a string > consisting of one character, U+0009, a tab. The string r"\t" is shown > as "\\t" and consists of two characters, REVERSE SOLIDUS and LATIN > SMALL LETTER T. That might be why

Re: os.path.isfile

2017-02-12 Thread Chris Angelico
On Mon, Feb 13, 2017 at 10:56 AM, Erik wrote: > Actually, while contriving those examples, I noticed that sometimes when > using string literal concatenation, the 'rawness' of the initial string is > sometimes applied to the following string and sometimes not: > "hello \the" r"worl\d" > 'hell

Re: os.path.isfile

2017-02-12 Thread Erik
On 12/02/17 23:56, Erik wrote: r"hello \the" "worl\d" 'hello \\theworl\\d' Slightly surprising. The concatenated string adopts the initial string's 'rawness'. "hello \the" r"worl\d" "\t" 'hello \theworl\\d\t' The initial string is not raw, the following string is. The string following _that

Re: os.path.isfile

2017-02-12 Thread Erik
On 12/02/17 04:53, Steve D'Aprano wrote: py> s = r'documents\' File "", line 1 s = r'documents\' ^ SyntaxError: EOL while scanning string literal (I still don't understand why this isn't just treated as a bug in raw string parsing and fixed...) I would imagine that i

Re: os.path.isfile

2017-02-11 Thread Steve D'Aprano
On Sun, 12 Feb 2017 03:20 pm, eryk sun wrote: > On Sun, Feb 12, 2017 at 3:52 AM, Steve D'Aprano > wrote: >> In Python, you should always use forward slashes for paths, even on >> Windows. > > There are cases where slash doesn't work (e.g. some command lines; > \\?\ prefixed paths; registry subke

Re: os.path.isfile

2017-02-11 Thread Chris Angelico
On Sun, Feb 12, 2017 at 3:20 PM, eryk sun wrote: > On Sun, Feb 12, 2017 at 3:52 AM, Steve D'Aprano > wrote: >> In Python, you should always use forward slashes for paths, even on Windows. > > There are cases where slash doesn't work (e.g. some command lines; > \\?\ prefixed paths; registry subkey

Re: os.path.isfile

2017-02-11 Thread eryk sun
On Sun, Feb 12, 2017 at 3:52 AM, Steve D'Aprano wrote: > In Python, you should always use forward slashes for paths, even on Windows. There are cases where slash doesn't work (e.g. some command lines; \\?\ prefixed paths; registry subkey paths), so it's simpler to follow a rule to always convert

Re: os.path.isfile

2017-02-11 Thread Steve D'Aprano
On Sat, 11 Feb 2017 05:11 am, epro...@gmail.com wrote: > Hello NG > > Python 3.5.2 > > Windows 10 > > os.path.isfile() no recognise file with double dot? > > eg. match.cpython-35.pyc I doubt that very much. I expect you are probably writing something like this: path = 'My Documents\testin

Re: os.path.isfile

2017-02-11 Thread Steve D'Aprano
On Sat, 11 Feb 2017 06:50 am, Vincent Vande Vyvre wrote: > Le 10/02/17 à 19:11, epro...@gmail.com a écrit : >> Hello NG >> >> Python 3.5.2 >> >> Windows 10 >> >> os.path.isfile() no recognise file with double dot? >> >> eg. match.cpython-35.pyc >> >> Please somebody know something about that? >> >

Re: os.path.isfile

2017-02-10 Thread eryk sun
On Fri, Feb 10, 2017 at 9:09 PM, Vincent Vande Vyvre wrote: > Le 10/02/17 à 22:03, Vincent Vande Vyvre a écrit : >> Le 10/02/17 à 21:36, Peter Otten a écrit : >>> Vincent Vande Vyvre wrote: Le 10/02/17 à 19:11, epro...@gmail.com a écrit : > > Python 3.5.2 > > Windows 10 >

Re: os.path.isfile

2017-02-10 Thread Vincent Vande Vyvre
Le 10/02/17 à 22:03, Vincent Vande Vyvre a écrit : Le 10/02/17 à 21:36, Peter Otten a écrit : Vincent Vande Vyvre wrote: Le 10/02/17 à 19:11, epro...@gmail.com a écrit : Hello NG Python 3.5.2 Windows 10 os.path.isfile() no recognise file with double dot? eg. match.cpython-35.pyc Please s

Re: os.path.isfile

2017-02-10 Thread Vincent Vande Vyvre
Le 10/02/17 à 21:36, Peter Otten a écrit : Vincent Vande Vyvre wrote: Le 10/02/17 à 19:11, epro...@gmail.com a écrit : Hello NG Python 3.5.2 Windows 10 os.path.isfile() no recognise file with double dot? eg. match.cpython-35.pyc Please somebody know something about that? Thank You in adv

Re: os.path.isfile

2017-02-10 Thread Peter Otten
Vincent Vande Vyvre wrote: > Le 10/02/17 à 19:11, epro...@gmail.com a écrit : >> Hello NG >> >> Python 3.5.2 >> >> Windows 10 >> >> os.path.isfile() no recognise file with double dot? >> >> eg. match.cpython-35.pyc >> >> Please somebody know something about that? >> >> Thank You in advance >> > In

Re: os.path.isfile

2017-02-10 Thread MRAB
On 2017-02-10 19:50, Vincent Vande Vyvre wrote: Le 10/02/17 à 19:11, epro...@gmail.com a écrit : Hello NG Python 3.5.2 Windows 10 os.path.isfile() no recognise file with double dot? eg. match.cpython-35.pyc Please somebody know something about that? Thank You in advance Interesting, you'

Re: os.path.isfile

2017-02-10 Thread Chris Angelico
On Sat, Feb 11, 2017 at 6:50 AM, Vincent Vande Vyvre wrote: > Interesting, you're right. > > Python 3.4.3 (default, Nov 17 2016, 01:08:31) > [GCC 4.8.4] on linux > Type "help", "copyright", "credits" or "license" for more information. import os os.path.isfile('/home/vincent/oqapy-3/

Re: os.path.isfile

2017-02-10 Thread Vincent Vande Vyvre
Le 10/02/17 à 19:11, epro...@gmail.com a écrit : Hello NG Python 3.5.2 Windows 10 os.path.isfile() no recognise file with double dot? eg. match.cpython-35.pyc Please somebody know something about that? Thank You in advance Interesting, you're right. Python 3.4.3 (default, Nov 17 2016, 01

Re: os.path.isfile and wildcard for directory name

2010-12-30 Thread smainklh
Hi Cameron, Ok, i'll try that :) Thanks Smaine Selon Cameron Simpson : > On 30Dec2010 09:36, smain...@free.fr wrote: > | I want to test if a file exists but my path contain a directory name that > | differs from a server to another. > | In shell i would have done something like that : > | #!/b

Re: os.path.isfile and wildcard for directory name

2010-12-30 Thread Peter Otten
smain...@free.fr wrote: > I'm just beginning to learn python language and i'm trying to do something > and i can't figure it out. > > I want to test if a file exists but my path contain a directory name that > differs from a server to another. > In shell i would have done something like that : >

Re: os.path.isfile and wildcard for directory name

2010-12-30 Thread Cameron Simpson
On 30Dec2010 09:36, smain...@free.fr wrote: | I want to test if a file exists but my path contain a directory name that | differs from a server to another. | In shell i would have done something like that : | #!/bin/bash | mypath=/dire*/directory02/ | myfile=filename | myfile=toto | if [ -f $mypat

Re: os.path.isfile and wildcard for directory name

2010-12-30 Thread Javier Collado
Hello, 2010/12/30 : > How can i do the same thing (wildcard in a directory name) in python please ? You can get the contents of a directory with os.listdir and filter with fnmatch.fnmatch more or less as in the example from the documentation: - import fnmatch import os for f

Re: os.path.isfile()

2007-07-01 Thread 7stud
On Jul 1, 3:36 am, Duncan Booth <[EMAIL PROTECTED]> wrote: > 7stud <[EMAIL PROTECTED]> wrote: > > Here is a program to print out the files in a directory: > > > --- > > import os > > > myfiles = os.listdir("../") > > print myfiles > > > for afile in myfiles: > > print afile > > if o

Re: os.path.isfile()

2007-07-01 Thread Duncan Booth
7stud <[EMAIL PROTECTED]> wrote: > Here is a program to print out the files in a directory: > > --- > import os > > myfiles = os.listdir("../") > print myfiles > > for afile in myfiles: > print afile > if os.path.isfile(afile): > print afile, "___file" > if os.path.i

Re: os.path.isfile() error

2007-04-07 Thread Steve Holden
[EMAIL PROTECTED] wrote: > On Apr 7, 4:56 pm, "7stud" <[EMAIL PROTECTED]> wrote: >> Here's the code: >> >> import os, os.path, pprint >> >> mydir = "/Users/me/2testing" >> >> files = [file for file in os.listdir(mydir)] >> pprint.pprint(files) >> >> print os.path.join(mydir, "helloWorl

Re: os.path.isfile() error

2007-04-07 Thread 7stud
On Apr 7, 2:56 am, "7stud" <[EMAIL PROTECTED]> wrote: > Here's the code: > > import os, os.path, pprint > > mydir = "/Users/me/2testing" > > files = [file for file in os.listdir(mydir)] > pprint.pprint(files) > > print os.path.join(mydir, "helloWorld.py") > > files = [file > for file i

Re: os.path.isfile() error

2007-04-07 Thread mik3l3374
On Apr 7, 4:56 pm, "7stud" <[EMAIL PROTECTED]> wrote: > Here's the code: > > import os, os.path, pprint > > mydir = "/Users/me/2testing" > > files = [file for file in os.listdir(mydir)] > pprint.pprint(files) > > print os.path.join(mydir, "helloWorld.py") > > files = [file > for file i

Re: os.path.isfile() error

2007-04-07 Thread John Machin
On Apr 7, 6:56 pm, "7stud" <[EMAIL PROTECTED]> wrote: > Here's the code: > > import os, os.path, pprint > > mydir = "/Users/me/2testing" > > files = [file for file in os.listdir(mydir)] > pprint.pprint(files) > > print os.path.join(mydir, "helloWorld.py") > > files = [file > for file i

Re: os.path.isfile() error

2007-04-07 Thread Peter Otten
7stud wrote: > Here's the code: > > import os, os.path, pprint > > mydir = "/Users/me/2testing" > > files = [file for file in os.listdir(mydir)] > pprint.pprint(files) > > print os.path.join(mydir, "helloWorld.py") > > files = [file > for file in os.listdir(mydir) > if os.path.isf

Re: os.path.isfile with *.tar.gz

2007-03-15 Thread Bruno Desthuilliers
> Boudreau, Emile wrote: (snip) >> I have tried variations of: os.path.isfile( os.path.join("C:\\temp\\", >> "rqp-win32-app", "*.tar.gz")) As a side note, the whole point of os.path is to help writing portable code. So passing an os.specific path componant is somewhat counter productive !-) (s

Re: os.path.isfile with *.tar.gz

2007-03-15 Thread Tim Golden
Boudreau, Emile wrote: > Hello All, > I'm new to Python and it looks like people that post here do get > a good answer back so I figured I'd try my luck. > > I'm trying to check a directory to see if there is a file that has the > name "startOfString" + some version number + "inst.tar.gz

Re: os.path.isfile with *.tar.gz

2007-03-15 Thread Steve Holden
Boudreau, Emile wrote: > Hello All, > I'm new to Python and it looks like people that post here do get > a good answer back so I figured I'd try my luck. > > I'm trying to check a directory to see if there is a file that has the > name "startOfString" + some version number + "inst.tar.gz