Hi,
import os
if os.path.exists('/path/to/file'):
# File exists
else:
# File doesn't exist
It works for files as well as directories.
Regards,
Vikram U Shenoy
___
Tutor maillist - Tutor@python.org
hello there,
i am writing an app for linux. what command would be easiest to test and see
if a certain file exist ?
i was going to do something like this
try:
file = open('/path/to/file', 'rb')
return True
except:
return False
but i thought that there would be an easier way.
thanks
shawn bright wrote:
hello there,
i am writing an app for linux. what command would be easiest to test
and see if a certain file exist ?
i was going to do something like this
try:
file = open('/path/to/file', 'rb')
return True
except:
return False
You should except IOError
On 1/4/07, Luke Paireepinart [EMAIL PROTECTED] wrote:
shawn bright wrote:
hello there,
i am writing an app for linux. what command would be easiest to test
and see if a certain file exist ?
i was going to do something like this
try:
file = open('/path/to/file', 'rb')
return True
thanks, luke, Andre.
appreciate it a lot
shawn
On 1/3/07, Andre Roberge [EMAIL PROTECTED] wrote:
On 1/4/07, Luke Paireepinart [EMAIL PROTECTED] wrote:
shawn bright wrote:
hello there,
i am writing an app for linux. what command would be easiest to test
and see if a certain file
On Thu, 4 Jan 2007, Andre Roberge wrote:
i am writing an app for linux. what command would be easiest to test
and see if a certain file exist ?
i was going to do something like this
try:
file = open('/path/to/file', 'rb')
return True
except:
return False
You should