views:

48

answers:

1

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

A: 

There 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 seperate arguments, D:\Documents, and, Settings\BDE\Desktop\cdburn.jpg. If you, you need to quoate any filename that has spaces in it.

Simon Callan