Dec-04-2018, 02:22 PM
I am running a Python script, which is supposed to check whether a directory already exists:
import os
and fail while trying to display the content of the inexistent directory.
What is wrong in my code?
My code runs correctly if run inside the console Python interpreter.
My code always fails if run as a script on the very same console.
Fabrizio
import os
#!/usr/bin/env python source_dir = <inexistent directory> if (os.path.isdir(source_dir)): print "source directory not found" else: print "source directory found" os.system("ls -l " + source_dir)will always enter the else statement (directory found) for an non-existing directory
and fail while trying to display the content of the inexistent directory.
What is wrong in my code?
My code runs correctly if run inside the console Python interpreter.
My code always fails if run as a script on the very same console.
Fabrizio