os.path.dirname(sys.argv[0]) always returns nothing

Chris Angelico rosuav at gmail.com
Mon Aug 1 19:53:30 CEST 2011

On Mon, Aug 1, 2011 at 6:38 PM, happykid <psyking841 at gmail.com> wrote:
> I want to use this function to get the directory path of the running
> script, but it always returns empty string. Can anyone help me solve
> this? Thank you.

As long as you haven't changed directory since startup, you should be
able to use os.path.abspath(sys.argv[0]) to get the absolute path
name. It'll automatically fill in the path from the current directory
if it's not provided.

See: http://docs.python.org/py3k/library/os.path.html#os.path.abspath


More information about the Python-list mailing list