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

P

poggle.themammal

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
 
S

Simon Forman

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
 
D

Dennis Lee Bieber

"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
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top