command line arguments

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ltauxe
    New Member
    • Oct 2009
    • 1

    command line arguments

    Here's a very simple script:
    Code:
    #!/usr/bin/env python
    import sys
    print sys.argv
    running this, I get:

    C:\tmp>tmp.py -h
    ['C:\\tmp\\tmp.p y']

    two things are wrong: 1) there are two '\'s and 2) the argument -h is missing.
    I'm running Enthought Python Distribution on Windows XP under Parallels on a Mac. I never had this problem before.

    Lisa
    Last edited by bvdet; Oct 14 '09, 01:09 PM. Reason: Add code tags
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    In Python string literals, the double backslash "\\" represents a single backslash character.
    Code:
    >>> s = 'C:\\tmp\\tmp.py'
    >>> s
    'C:\\tmp\\tmp.py'
    >>> print s
    C:\tmp\tmp.py
    >>>
    I can't explain why the "-h" argument is not in sys.argv. I works properly on my XP system.

    Comment

    • Glenton
      Recognized Expert Contributor
      • Nov 2008
      • 391

      #3
      Hi
      I run
      "python testsys.py -h" in a terminal and get
      ['testsys.py', '-h']

      I'm running on Ubuntu 9.10.

      Sorry I can't be of more help.

      Comment

      Working...