0

I been using os.path.abspath(sys.argv[0]) for getting the path where my exe runs always (doesn't matter where it was executed from) but python 2.x there is a problem with sys.argv http://bugs.python.org/issue2128 with unicode trying to use the script path for glade (PYGTK) file

self.gladeloc = os.path.join(os.path.dirname(os.path.abspath(sys.argv[0])),"file.glade")
print self.gladeloc #prints fine C:\Users\фдсфгс\Desktop\ using idle console
self.builder.add_from_file(self.gladeloc) #prints C:\Users\пїЅпїЅпїЅ\Desktop\

I get the following error is there alternative for getting exe location on disk (doesnt matter where opened) i have searched other questions and it seems there is no alternative without 2 problems

1 get files location even if executed from different place

2 unicode/utf-8 support pygtk doesn't support python 3 (fixed sys.argv) so I can't just upgrade

1 Answers1

0

Found this Answer It will change the sys.argv function to return unicode for py2.x. But it seems to me that it works differently than original sys.argv atleast for Idle console it showed path of python.exe for cmd console it showed correct file.py but I have found I think a better solution doesn't edit the sys.argv and idle console shows the right file.py unicode type os.path.abspath(sys.argv[0].decode('mbcs')) feedback on this will be great maybe I'm missing something? I will try do more testing and update if its not working as it should

Community
  • 1
  • 1