<div dir="ltr"><br><br><div class="gmail_quote">On Mon, Aug 1, 2011 at 1:38 PM, happykid <span dir="ltr"><<a href="mailto:psyking841@gmail.com">psyking841@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
I want to use this function to get the directory path of the running<br>
script, but it always returns empty string. Can anyone help me solve<br>
this? Thank you.<br>
<font color="#888888">--<br></font></blockquote><div><br></div><div>sys.argv[0] is the name of the script you called. If you call "python spam.py", sys.argv[0] will be spam.py. Not /full/path/spam.py. Just spam.py. And the directory part of "spam.py" is "". You'll have to call os.path.abspath(sys.argv[0]) to get the full path, then get dirname.</div>
</div><br></div>