Get directory of current script in Python
Can be done by getting the directory part of __file__
or sys.argv[0]
, in case the former is not available:
os.path.dirname(os.path.realpath(__file__))
os.path.dirname(os.path.realpath(sys.argv[0]))
Can be done by getting the directory part of __file__
or sys.argv[0]
, in case the former is not available:
os.path.dirname(os.path.realpath(__file__))
os.path.dirname(os.path.realpath(sys.argv[0]))