Python (windows) will open files from command line, but not from a script launched from eclipse
I'm pretty new to writing python for windows (linux is no problem), and am having problems getting python to recognize files when running scripts, though it behaves fine in the command line
What am I doing wrong here?开发者_高级运维
def verifyFile(x):
#
return os.path.isfile(x)
This will return true (with a valid file, of course) when called from the python command line, but when I run the script from eclipse, or launch it from windows, it ALWAYS returns false. Any thoughts on why this is?
I've tried passing pathnames like this: D:\Documents and Settings\BDE\Desktop\cdburn.jpg and like this: D:/Documents and Settings/BDE/Desktop/cdburn.jpg
I've changed sys,argv[0] to ''
I've tried this:
def verifyFile(x):
#
try:
f = open(x, 'r')
f.close()
return True
except:
return False
and am getting no love!
Any help would be appreciated.
Thanks
Blake
There is not really enough information here to debug your issue, but I have a suspicion.
Try adding the line
print sys.argv
to the start of your code, and see what the actual arguments that are being passed in to your program. I have a feeling that you will find the the filename D:\Documents and Settings\BDE\Desktop\cdburn.jpg
is being split into 3 separate arguments, D:\Documents
, and
, Settings\BDE\Desktop\cdburn.jpg
. If so, you need to quote any filename that has spaces in it.
精彩评论