Access to sys.argv when python interpreter is invoked in some modes like 'python -c "command"'

Discussion in 'Python' started by poggle.themammal@gmail.com, Aug 20, 2006.

  1. Guest

    The python tutorial says
    "When the script name is given as '-' (meaning standard input),
    sys.argv[0] is set to '-'. When -c command is used, sys.argv[0] is
    set to '-c'. " but when we use a command say 'python -c "command"'
    where can we access "sys.argv" (are there some commands where
    "sys.argv" is accessed. I can run 'python -c "import sys sys.argv", I
    get an error message

    -Tiro
    , Aug 20, 2006
    #1
    1. Advertising

  2. Simon Forman Guest

    wrote:
    > The python tutorial says
    > "When the script name is given as '-' (meaning standard input),
    > sys.argv[0] is set to '-'. When -c command is used, sys.argv[0] is
    > set to '-c'. " but when we use a command say 'python -c "command"'
    > where can we access "sys.argv" (are there some commands where
    > "sys.argv" is accessed. I can run 'python -c "import sys sys.argv", I
    > get an error message
    >
    > -Tiro


    When you get an error message, and you ask a question concerning the
    error message, *post* the error message.

    But first, read it yourself. It will probably tell you what's wrong.
    That's why it exists.

    Meantime, what's your question?


    BTW, "import sys sys.argv" is invalid python. When putting code
    statements together on one line like this you must separate them with
    ";". I.e. "import sys; sys.argv". Note that this will still not do
    what (I'm guessing) you want because this code is not being executed
    interactively. It will simply "get" the value of sys.argv and then
    throw it away. Try "import sys; print sys.argv", if you want to print
    the value of sys.argv.

    Happy coding,
    ~Simon
    Simon Forman, Aug 20, 2006
    #2
    1. Advertising

  3. On 20 Aug 2006 11:16:00 -0700, declaimed the
    following in comp.lang.python:

    > "sys.argv" is accessed. I can run 'python -c "import sys sys.argv", I
    > get an error message
    >

    "import sys" is A statement.
    "sys.argv" is a second, meaningless, statement...

    "import sys sys.argv" should be a syntax error...

    C:\Documents and Settings\Dennis Lee Bieber>
    python -c "import sys; print sys.argv"
    ['-c']

    C:\Documents and Settings\Dennis Lee Bieber>

    Note the ";" to separate statements
    --
    Wulfraed Dennis Lee Bieber KD6MOG

    HTTP://wlfraed.home.netcom.com/
    (Bestiaria Support Staff: )
    HTTP://www.bestiaria.com/
    Dennis Lee Bieber, Aug 20, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bret

    char **argv vs. char* argv[]

    Bret, Aug 31, 2003, in forum: C Programming
    Replies:
    21
    Views:
    4,558
    Richard Heathfield
    Sep 3, 2003
  2. David
    Replies:
    10
    Views:
    5,924
    Richard Heathfield
    Sep 15, 2003
  3. Hal Styli
    Replies:
    14
    Views:
    1,615
    Old Wolf
    Jan 20, 2004
  4. =?ISO-8859-1?Q?Thomas_N=FCcker?=

    sys.argv[0] - 'module' object has no attribute 'argv'

    =?ISO-8859-1?Q?Thomas_N=FCcker?=, Jun 30, 2003, in forum: Python
    Replies:
    0
    Views:
    886
    =?ISO-8859-1?Q?Thomas_N=FCcker?=
    Jun 30, 2003
  5. Chris Allen
    Replies:
    3
    Views:
    315
    Arnau Sanchez
    Aug 29, 2007
Loading...

Share This Page