Chris You are the man ... that's works perfectly ... great :)
And thank you all ... who ever helped me Thanks O.S.K On Fri, Apr 24, 2009 at 6:37 PM, Paul Molodowitch <[email protected]>wrote: > > Yeah, you're right, it looks like that should work for invoking from > the command-line (which was what kurian was asking about). > > I guess when I was looking into it, I was trying to solve a slightly > different problem - have a script that would be able to tell what it's > location was, regardless of whether it was invoked from the > command-line, or from execfile (where > os.path.join(sys.path[0],sys.argv[0]) doesn't work). > > - Paul > > > Reply > > > Hi > > On Fri, Apr 24, 2009 at 12:32 PM, Chris G <[email protected]> wrote: > > This seems pretty reliable: > > > > os.path.join(sys.path[0],sys.argv[0]) > > > > > > On Fri, Apr 24, 2009 at 10:48 AM, Paul Molodowitch <[email protected]> > > wrote: > >> > >> Unfortunately, I seem to recall being frustrated by this at some > >> point, because for what seems to be a very simple problem, there isn't > >> a very simple solution. There's a lot of different ways to go about > >> it, but each seems to have some issues: > >> > >> __file__ isn't always defined (forget exactly what situations it won't > >> exist) > >> sys.argv[0] often doesn't have any path info > >> os.getcwd() can vary - you don't have to be in the same cwd as the > >> script you're running > >> > >> I think the 'most' reliable solution I found was: > >> > >> import inspect > >> print inspect.getsourcefile( lambda:None ) > >> > >> (grabbed from this thread: > >> http://mail.python.org/pipermail/python-list/2003-December/242365.html > >> - jason.osipa was also hinting this way, I think) > >> > >> However, I think there are situations where this can fail, too (again, > >> don't remember exactly - I think when using .pyc's, that have > >> subsequently moved, perhaps? I remember that was tripping up one of > >> these methods, anyway.) > >> > >> > >> > >> 2009/4/24 Bård Henriksen <[email protected]>: > >> > > >> > use __file__ > >> > > >> > eg: > >> > > >> > def get_my_path(): > >> > """ > >> > Return the path to wherever this script file is stored > >> > """ > >> > return os.path.dirname(__file__) > >> > > >> > Bård > >> > > >> > > > >> > > >> > >> > > > > > > > > > > > > > -- സ്നേഹിക്കയില്ല ഞാന് നോവുമാത്മാവിനെ സ്നേഹിച്ചിടാത്തൊരു തത്വശാസ്ത്രത്തെയും -- വയലാര് "തെറ്റു ചെയ്യുന്നവന് മനുഷ്യനാണു്; അതിനെക്കുറിച്ചോര്ത്തു ദു:ഖിക്കുന്നവന് മഹര്ഷിയാണു്; എന്നാല് അതില് അഭിമാനം കൊള്ളുന്നവന് പിശാചാണു്." - തോമസ് മുള്ളര് --~--~---------~--~----~------------~-------~--~----~ http://groups.google.com/group/python_inside_maya -~----------~----~----~----~------~----~------~--~---
