On Thu, 02 Nov 2006 01:44:25 +1100, Ben Finney wrote:
[EMAIL PROTECTED] [EMAIL PROTECTED] writes:
Ben Finney wrote:
[EMAIL PROTECTED] [EMAIL PROTECTED] writes:
You could try to read the file, if that fails it doesn't exist:
Except that there are other conditions than File doesn't
Steven D'Aprano wrote:
But there can be a race condition between os.path.exists returning True
and you trying to open the file, if some other process deletes or renames
the file in the meantime.
if you'd used a threaded newsreader, you would have seen the code that
as follows was referring
John Salerno wrote:
What is the best way to check if a file already exists in the current
directory? I saw os.path.isfile(), but I'm not sure if that does more
than what I need.
I just want to check if a file of a certain name exists before the user
creates a new file of that name.
[EMAIL PROTECTED] [EMAIL PROTECTED] writes:
You could try to read the file, if that fails it doesn't exist:
try:
f = open('xxx')
except IOError:
f = open('xxx', 'w')
print file doesn't exist
print f
Except that there are other conditions than File doesn't exist that
can cause
Ben Finney wrote:
[EMAIL PROTECTED] [EMAIL PROTECTED] writes:
You could try to read the file, if that fails it doesn't exist:
try:
f = open('xxx')
except IOError:
f = open('xxx', 'w')
print file doesn't exist
print f
Except that there are other conditions than File
[EMAIL PROTECTED] [EMAIL PROTECTED] writes:
Ben Finney wrote:
[EMAIL PROTECTED] [EMAIL PROTECTED] writes:
You could try to read the file, if that fails it doesn't exist:
Except that there are other conditions than File doesn't exist
that can cause an 'open' to fail.
Ok, true. You
Ben Finney wrote:
[EMAIL PROTECTED] [EMAIL PROTECTED] writes:
Ben Finney wrote:
[EMAIL PROTECTED] [EMAIL PROTECTED] writes:
You could try to read the file, if that fails it doesn't exist:
Except that there are other conditions than File doesn't exist
that can cause an 'open' to
On Nov 1, 3:44 pm, Ben Finney [EMAIL PROTECTED]
wrote:
[EMAIL PROTECTED] [EMAIL PROTECTED] writes:
Ben Finney wrote:
[EMAIL PROTECTED] [EMAIL PROTECTED] writes:
You could try to read the file, if that fails it doesn't exist:
Except that there are other conditions than File doesn't
[EMAIL PROTECTED] wrote:
os.path.exists() checks if a path exists, so a directory as argument
also returns True
the original requirement was to check if a file of a certain name
exists before the user creates a new file of that name.
if you want to check for files only, use the
What is the best way to check if a file already exists in the current
directory? I saw os.path.isfile(), but I'm not sure if that does more
than what I need.
I just want to check if a file of a certain name exists before the user
creates a new file of that name.
Thanks.
--
John Salerno wrote:
What is the best way to check if a file already exists in the current
directory? I saw os.path.isfile(), but I'm not sure if that does more
than what I need.
I just want to check if a file of a certain name exists before the user
creates a new file of that name.
At Tuesday 31/10/2006 18:01, John Salerno wrote:
What is the best way to check if a file already exists in the current
directory? I saw os.path.isfile(), but I'm not sure if that does more
than what I need.
os.access(full_filename, os.F_OK)
http://docs.python.org/lib/os-file-dir.html
I just
If you want to open the file for writing just open it
with append mode. open(¨filename, a). If it
doesn't exist - it'll create it, and if it does it'll
start appending to the file
For reading - os.path.exists(filename). Or (doesn't
make much sense, but still) try to open it for reading
and
On Oct 31, 4:01 pm, John Salerno [EMAIL PROTECTED] wrote:
What is the best way to check if a file already exists in the current
directory? I saw os.path.isfile(), but I'm not sure if that does more
than what I need.
I just want to check if a file of a certain name exists before the user
[EMAIL PROTECTED] writes:
On Oct 31, 4:01 pm, John Salerno [EMAIL PROTECTED] wrote:
What is the best way to check if a file already exists in the
current directory? I saw os.path.isfile(), but I'm not sure if
that does more than what I need.
I see that 'os.path.exists' has already been
On Tuesday 31 October 2006 16:01, John Salerno
wrote:
What is the best way to check if a file already
exists in the current directory? I saw
os.path.isfile(), but I'm not sure if that does
more than what I need.
I just want to check if a file of a certain
name exists before the user
16 matches
Mail list logo