0

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

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.