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

Thijs Engels thijs at buckazoids.com
Mon Aug 1 19:55:11 CEST 2011

On Mon, 01 Aug 2011 10:38 -0700, "happykid" <psyking841 at gmail.com>
> 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.
> -- 
> http://mail.python.org/mailman/listinfo/python-list

I think this is what you are after:

import os.path

path = os.path.abspath(os.path.dirname(__file__))

argv[0] returns the name of the current file (string), but no path
information if I recall correct.


More information about the Python-list mailing list