#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    25
    Rep Power
    0

    Create a variable just before running the script


    Hi, it is hard to explained what I want, but I will try. I writing an script that I want the user to create the variable when the run ths script. Something like this

    The user running the script:

    python scriptname.py 34

    Code:
    number = "what ever the user input after scriptname.py"
    print number
    I want the number 34 that the user wrote after scriptname.py be inside my script like a regular variable. Thanks in advance
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,711
    Rep Power
    480
    # try this program saved as p.py with command line use
    # $ python p.py arguments like 43 34 I mean.
    import sys
    print sys.argv
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    25
    Rep Power
    0
    Originally Posted by b49P23TIvg
    # try this program saved as p.py with command line use
    # $ python p.py arguments like 43 34 I mean.
    import sys
    print sys.argv
    Thanks, is exctly what I was looking for.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    5
    Rep Power
    0
    You use the sys module

    Code:
    import sys
    print sys.argv[1]
    python script.py variable

IMN logo majestic logo threadwatch logo seochat tools logo