James Porter James Porter - 4 months ago 11
Python Question

Python: try/except OSerror errno 2

I'm writing a script where the user selects a directory and hits ok.

That I've sussed pretty easily, but I'm trying to sort error handling side, but it's not going to plan.

Essentially, I want to continue the script unless OSError Errno 2 is called.

at the moment, I have:
import IOError

if ok==1:
folder = selection
except IOError:
print "Select a folder, not a file"

I've tried using except without IOError, but that causes problems elsewhere in the script (In a different function completely)

Anyone have a suggestions?



Use os.path.isdir(folder)

Python - isdir