get script path

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • hg

    #1

    get script path

    Hi,

    must I parse argv[0] to get it, or is there an easier way (that works under
    Windows and *nix)?

    Ex:

    python /home/hg/test/test.py ==test.py #knows it is in /home/hg/test

    Thanks,

    hg



  • hg

    #2
    Re: get script path

    hg wrote:
    Hi,
    >
    must I parse argv[0] to get it, or is there an easier way (that works
    under Windows and *nix)?
    >
    Ex:
    >
    python /home/hg/test/test.py ==test.py #knows it is in /home/hg/test
    >
    Thanks,
    >
    hg
    got it: os.path.dirname (sys.argv [0])

    Comment

    • Rob Wolfe

      #3
      Re: get script path


      hg wrote:
      Hi,
      >
      must I parse argv[0] to get it, or is there an easier way (that works under
      Windows and *nix)?
      >
      Ex:
      >
      python /home/hg/test/test.py ==test.py #knows it is in /home/hg/test
      IMHO it is easy enough:
      >>dname, fname = os.path.split("/home/hg/test/test.py")
      >>dname
      '/home/hg/test'

      --
      HTH,
      Rob

      Comment

      • hg

        #4
        Re: get script path

        Rob Wolfe wrote:
        >
        hg wrote:
        >Hi,
        >>
        >must I parse argv[0] to get it, or is there an easier way (that works
        >under Windows and *nix)?
        >>
        >Ex:
        >>
        >python /home/hg/test/test.py ==test.py #knows it is in /home/hg/test
        >
        IMHO it is easy enough:
        >
        >>>dname, fname = os.path.split("/home/hg/test/test.py")
        >>>dname
        '/home/hg/test'
        >
        --
        HTH,
        Rob
        thanks

        Comment

        Working...