Re: pathlib.Path.is_file vs os.path.isfile difference

2024-03-10 Thread Barry via Python-list
> On 10 Mar 2024, at 14:49, Thomas Passin via Python-list > wrote: > > That and there's a registry setting: > > https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation > Yep that and rules about size of parts of the path. Barry -- https://mail.python.org/mailm

Re: pathlib.Path.is_file vs os.path.isfile difference

2024-03-10 Thread Thomas Passin via Python-list
On 3/10/2024 9:33 AM, Albert-Jan Roskam wrote: On Mar 10, 2024 12:59, Thomas Passin via Python-list wrote: On 3/10/2024 6:17 AM, Barry wrote: > > >> On 8 Mar 2024, at 23:19, Thomas Passin via Python-list wrote: >> >> We just learned a few posts back that it

Re: pathlib.Path.is_file vs os.path.isfile difference

2024-03-10 Thread Albert-Jan Roskam via Python-list
On Mar 10, 2024 12:59, Thomas Passin via Python-list wrote: On 3/10/2024 6:17 AM, Barry wrote: > > >> On 8 Mar 2024, at 23:19, Thomas Passin via Python-list wrote: >> >> We just learned a few posts back that it might be specific to Linux; I ran it on

Re: pathlib.Path.is_file vs os.path.isfile difference

2024-03-10 Thread Thomas Passin via Python-list
On 3/10/2024 6:17 AM, Barry wrote: On 8 Mar 2024, at 23:19, Thomas Passin via Python-list wrote: We just learned a few posts back that it might be specific to Linux; I ran it on Windows. Depending on the exact win32 api used there is a 257 limit on windows. The 257 includes 2 for the dev

Re: pathlib.Path.is_file vs os.path.isfile difference

2024-03-10 Thread Barry via Python-list
> On 8 Mar 2024, at 23:19, Thomas Passin via Python-list > wrote: > > We just learned a few posts back that it might be specific to Linux; I ran it > on Windows. Depending on the exact win32 api used there is a 257 limit on windows. The 257 includes 2 for the device, C:, and 255 for the pat

Re: pathlib.Path.is_file vs os.path.isfile difference

2024-03-08 Thread Grant Edwards via Python-list
On 2024-03-08, Thomas Passin via Python-list wrote: > >> Hi, I tested this with Python 3.8. Good to know that this was fixed! > > We just learned a few posts back that it might be specific to Linux; I > ran it on Windows. On Linux, the limit is imposed by the filesystem. Most of the "real" file

Re: pathlib.Path.is_file vs os.path.isfile difference

2024-03-08 Thread Thomas Passin via Python-list
Path(256 * "x").is_file()  # OSError > os.path.isfile(256 * "x")  # bool > Is this intended? Does pathlib try to resemble os.path as closely as > possible? You must have an very old version of Python.  I'm running 3.12.2 and

Re: pathlib.Path.is_file vs os.path.isfile difference

2024-03-08 Thread Albert-Jan Roskam via Python-list
s_file() # OSError > os.path.isfile(256 * "x") # bool > Is this intended? Does pathlib try to resemble os.path as closely as > possible? You must have an very old version of Python. I'm running 3.12.2 and it returns False. Either that or that

Re: pathlib.Path.is_file vs os.path.isfile difference

2024-03-08 Thread Thomas Passin via Python-list
;).is_file() # OSError os.path.isfile(256 * "x") # bool Is this intended? Does pathlib try to resemble os.path as closely as possible? You must have an very old version of Python. I'm running 3.12.2 and it returns False. It throws OSError with Python 3.11.8 on Linux.

Re: pathlib.Path.is_file vs os.path.isfile difference

2024-03-08 Thread Grant Edwards via Python-list
On 2024-03-08, Grant Edwards via Python-list wrote: >> OSError: [Errno 36] File name too long: >> 'x

Re: pathlib.Path.is_file vs os.path.isfile difference

2024-03-08 Thread Grant Edwards via Python-list
>> Path(256 * "x").is_file() # OSError >>> os.path.isfile(256 * "x") # bool >>> Is this intended? Does pathlib try to resemble os.path as closely as >>> possible? >> >> You must have an very old version of Python.

Re: pathlib.Path.is_file vs os.path.isfile difference

2024-03-08 Thread Grant Edwards via Python-list
On 2024-03-08, Thomas Passin via Python-list wrote: > On 3/8/2024 1:03 PM, Albert-Jan Roskam via Python-list wrote: >> Hi, >> I was replacing some os.path stuff with Pathlib and I discovered this: >> Path(256 * "x").is_file() # OSError >>

Re: pathlib.Path.is_file vs os.path.isfile difference

2024-03-08 Thread Thomas Passin via Python-list
On 3/8/2024 1:03 PM, Albert-Jan Roskam via Python-list wrote: Hi, I was replacing some os.path stuff with Pathlib and I discovered this: Path(256 * "x").is_file() # OSError os.path.isfile(256 * "x") # bool Is this intended? Does pathlib try to resemble o

pathlib.Path.is_file vs os.path.isfile difference

2024-03-08 Thread Albert-Jan Roskam via Python-list
Hi, I was replacing some os.path stuff with Pathlib and I discovered this: Path(256 * "x").is_file() # OSError os.path.isfile(256 * "x") # bool Is this intended? Does pathlib try to resemble os.path as closely as possible? Best wishes,

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 t

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.cpyth

Re: os.path.isfile

2017-02-10 Thread eryk sun
gt; >>>>> Python 3.5.2 >>>>> >>>>> Windows 10 >>>>> >>>>> os.path.isfile() no recognise file with double dot? >>>>> >>>>> eg. match.cpython-35.pyc >>>>> >>>> Intere

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

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

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 >> >>

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

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. &g

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

os.path.isfile

2017-02-10 Thread eproser
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 -- https://mail.python.org/mailman/listinfo/python-list

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

2010-12-30 Thread smainklh
mething like that : > | #!/bin/bash > | mypath=/dire*/directory02/ > | myfile=filename > | myfile=toto > | if [ -f $mypath/$myfile ] > [...] > > Check out the glob module: > http://docs.python.org/library/glob.html#module-glob > > Use it to do the glob, then os.pat

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

2010-12-30 Thread Peter Otten
'yadda2/alpha', 'yadda4/alpha', 'yadda7/alpha'] and then use isfile() to find the actual files: >>> import os >>> [f for f in candidates if os.path.isfile(f)] ['yadda5/alpha', 'yadda7/alpha'] Peter -- http://mail.python.org/mailman/listinfo/python-list

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

2010-12-30 Thread Cameron Simpson
$mypath/$myfile ] [...] Check out the glob module: http://docs.python.org/library/glob.html#module-glob Use it to do the glob, then os.path.isfile with a path constructed from the result: http://docs.python.org/library/os.path.html#os.path.isfile Cheers, -- Cameron Simpson DoD#743 http

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

os.path.isfile and wildcard for directory name

2010-12-30 Thread smainklh
Hi everyone, 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 : #!/bin/bash mypath=/d

Re: os.path.isfile()

2007-07-01 Thread 7stud
es > > > for afile in myfiles: > > print afile > > if os.path.isfile(afile): > > print afile, "___file" > > if os.path.isdir(afile): > > print afile, "___dir" > > print > > > >

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(

os.path.isfile()

2007-07-01 Thread 7stud
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.isdir(afile): print afile

SOLVED: Can os.remove followed by os.path.isfile disagree?

2007-06-06 Thread Paul Paterson
On Jun 6, 12:30 pm, "Roger Upole" <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > Can os.path.isfile(x) ever return True after os.remove(x) has > > successfully completed? (Windows 2003, Python 2.3) > > Yes. If another application has opened the fil

Re: Can os.remove followed by os.path.isfile disagree?

2007-06-06 Thread Roger Upole
[EMAIL PROTECTED] wrote: > Can os.path.isfile(x) ever return True after os.remove(x) has > successfully completed? (Windows 2003, Python 2.3) Yes. If another application has opened the file with FILE_SHARE_DELETE, os.remove succeeds but the file doesn't actually disappear until th

Re: Can os.remove followed by os.path.isfile disagree?

2007-06-06 Thread Paul Paterson
> Don't suppose you've got some kind of flashy software > running which intercepts OS file-manipulation calls for > Virus or Archiving purposes? > > TJG As I mentioned in another reply, this server is virtual and so is the drive. I'm wondering if this might also be significant. Paul -- http://

Re: Can os.remove followed by os.path.isfile disagree?

2007-06-06 Thread Paul Paterson
> > Is the file on a network drive by any chance? > > Diez No, but the server is actually a VMWare VM and the drive is a virtual drive. I'm thinking that this may be significant as it may be that the VMWare VHD driver is the "flashy software running which intercepts OS file- manipulation calls" t

Re: Can os.remove followed by os.path.isfile disagree?

2007-06-06 Thread Paul Paterson
Thanks for the response! > > I'd take the time to really examine the multiple threads of work you're > running > to make sure one of them isn't removing the file just as another creates it. > Better still, use a locking semaphore around the code the creates/deletes the > file > to guarantee mutu

Re: Can os.remove followed by os.path.isfile disagree?

2007-06-06 Thread Paul Paterson
Thanks for the quick and detailed response! > The most likely bet would seem to be a race condition > as you suggest below. Doesn't have to be from a thread > in your program, although I assume you know best about > your own filesystem ;) My first thought, after discounting the os.remove early r

Re: Can os.remove followed by os.path.isfile disagree?

2007-06-06 Thread Diez B. Roggisch
[EMAIL PROTECTED] wrote: > Can os.path.isfile(x) ever return True after os.remove(x) has > successfully completed? (Windows 2003, Python 2.3) > > We had a couple of failures in a server application that we cannot yet > reproduce in a simple case. Analysis of the code suggests

Re: Can os.remove followed by os.path.isfile disagree?

2007-06-06 Thread Tim Daneliuk
[EMAIL PROTECTED] wrote: > > The application is multithreaded so it is possible that another thread > writes to the file between the "remove" and the "isfile", but at the > end of the failure the file is actually not on the filesystem and I > don't believe there is a way that the file could be r

Re: Can os.remove followed by os.path.isfile disagree?

2007-06-06 Thread Tim Golden
[EMAIL PROTECTED] wrote: > Can os.path.isfile(x) ever return True after os.remove(x) has > successfully completed? (Windows 2003, Python 2.3) As an afterthought, have you tried NTFS auditing, or directory monitoring, such as: http://timgolden.me.uk/python/win32_ho

Re: Can os.remove followed by os.path.isfile disagree?

2007-06-06 Thread Tim Golden
[EMAIL PROTECTED] wrote: > Can os.path.isfile(x) ever return True after os.remove(x) has > successfully completed? (Windows 2003, Python 2.3) > > We had a couple of failures in a server application that we cannot yet > reproduce in a simple case. Analysis of the code suggests

Can os.remove followed by os.path.isfile disagree?

2007-06-06 Thread ppaterson
Can os.path.isfile(x) ever return True after os.remove(x) has successfully completed? (Windows 2003, Python 2.3) We had a couple of failures in a server application that we cannot yet reproduce in a simple case. Analysis of the code suggests that the only possible explanation is that the

Re: os.path.isfile() error

2007-04-07 Thread Steve Holden
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.isfile(os.path.join(dir, file) ) >> ] >> >> pprint.pprint(files) >> ---

Re: os.path.isfile() error

2007-04-07 Thread 7stud
ath.join(mydir, "helloWorld.py") > > files = [file > for file in os.listdir(mydir) > if os.path.isfile(os.path.join(dir, file) ) > ] > > pprint.pprint(files) > output: > > ['.DS_Store', 'cpTest', 'dir1', &

Re: os.path.isfile() error

2007-04-07 Thread mik3l3374
ath.join(mydir, "helloWorld.py") > > files = [file > for file in os.listdir(mydir) > if os.path.isfile(os.path.join(dir, file) ) > ] > > pprint.pprint(files) > output: > > ['.DS_Store', 'cpTest', 'dir1', &

Re: os.path.isfile() error

2007-04-07 Thread John Machin
ath.join(mydir, "helloWorld.py") > > files = [file > for file in os.listdir(mydir) > if os.path.isfile(os.path.join(dir, file) ) > ] > > pprint.pprint(files) > output: > > ['.DS_Store', 'cpTest', 'dir1', &

Re: os.path.isfile() error

2007-04-07 Thread Peter Otten
> > files = [file > for file in os.listdir(mydir) > if os.path.isfile(os.path.join(dir, file) ) That should be mydir, not dir. > ] > > pprint.pprint(files) > output: > > ['.DS_Store', 'cpTest', 'dir1', 'testfile1&#

os.path.isfile() error

2007-04-07 Thread 7stud
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.isfi

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 p

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

2007-03-15 Thread Tim Golden
t;startOfString" + some version number + "inst.tar.gz" > (component-8.3.16-inst.tar.gz) The version number will change quite > frequently so I just want to check if there is a file with that format name. > > I have tried variations of: os.path.isfile( os.path.join("C:\\temp

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

2007-03-15 Thread Steve Holden
t;startOfString" + some version number + "inst.tar.gz" > (component-8.3.16-inst.tar.gz) The version number will change quite > frequently so I just want to check if there is a file with that format name. > > I have tried variations of: os.path.isfile( os.path.join("C:\\temp

os.path.isfile with *.tar.gz

2007-03-15 Thread Boudreau, Emile
(component-8.3.16-inst.tar.gz) The version number will change quite frequently so I just want to check if there is a file with that format name. I have tried variations of: os.path.isfile( os.path.join("C:\\temp\\", "rqp-win32-app", "*.tar.gz")) but nothing seem to w