In <9797b629-3fba-4b90-920f-e42668359...@a12g2000vbf.googlegroups.com> happykid 
<psyking...@gmail.com> writes:

> 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.

What is the value of sys.argv[0]?  You're supposed to pass a full
pathname to os.path.dirname, like so:

>>> import os
>>> os.path.dirname('/a/b/c/d/e.txt')
'/a/b/c/d'
>>>

If sys.argv[0] is just the program name, then it doesn't have a path,
which is why you get no results from os.path.dirname:

>>> import os
>>> os.path.dirname('foo.py')
''
>>>

Are you trying to obtain the full pathname of the program?  That's an
entirely different question.

-- 
John Gordon                   A is for Amy, who fell down the stairs
gor...@panix.com              B is for Basil, assaulted by bears
                                -- Edward Gorey, "The Gashlycrumb Tinies"

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to