[Python-bugs-list] [ python-Bugs-423728 ] improper value of sys.argv with '-c' opt

noreply@sourceforge.net noreply@sourceforge.net
Sun, 13 May 2001 11:27:59 -0700


Bugs item #423728, was updated on 2001-05-13 08:04
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=423728&group_id=5470

Category: Python Interpreter Core
Group: Not a Bug
Status: Closed
Resolution: Invalid
Priority: 5
Submitted By: Frederic Giacometti (giacometti)
Assigned to: Nobody/Anonymous (nobody)
Summary: improper value of sys.argv with '-c' opt

Initial Comment:

Python 2,1 gives the following result:

---
python -c "import sys; print sys.argv"
[ '-c']
---

This is uncorrect and error-prone.

The two (possible) correct answers are:
    [] # strip off the '-c' stuff
  or
    [ '-c', 'import sys; print sys.argv'] # keep the '-c' stuff

  but ['-c'] alone is definitely uncorrect, as well as it does not make sense.

The source of the problem can explicitly be traced to file Python-2.1 -main.c, line 287:
  argv[_PyOS_optind] = "-c"; 
        (cf. [ python-Bugs-422678 ] (argv is modified in Py_Main())

which modifies 'argv' as side effect; this then messes up the initialization of 'sys.argv'.

Note: This bug is another side effect of [ python-Bugs-422678 ]

FG


----------------------------------------------------------------------

>Comment By: Frederic Giacometti (giacometti)
Date: 2001-05-13 11:27

Message:
Logged In: YES 
user_id=93657

I am sorry, but:

- 'some; arg' is a legal Unix/Windows file name
- it is better than than '-c'
- it does not 'bloat' the code, while creating problems elsewhere
- if you really want something 'as good as anything', as you say: --> use '', the empty name, or even None.

I wish you would give a little more consideration, and stop refering me to reference manuals, obfuscating 
the issue, and as if I did not know them.

Thanks,

FG


FG

----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2001-05-13 11:17

Message:
Logged In: YES 
user_id=31435

Not a bug.  Note also, e.g.,

> python -c "import sys; print sys.argv" a b c
['-c', 'a', 'b', 'c']

See the docs for sys.argv (in the Library manual) -- this 
is the documented and intended behavior.  argv[0] is (as 
also in C) supposed to be the name of the script, but when 
the script is passed literally on the cmdline there is no 
sensible name.  "-c" is as good as anything then.  
*Something* name-like must be passed in argv[0] else code 
that examines sys.argv would have to know whether or not 
Python started via -c.

argv[1:] is supposed contain the arguments to the script.  
Since the expression following -c *is* the script, it would 
be incorrect to leave that in argv:  the script is not an 
argument to itself, after all.


----------------------------------------------------------------------

Comment By: Frederic Giacometti (giacometti)
Date: 2001-05-13 11:17

Message:
Logged In: YES 
user_id=93657

Actually, I need to correct something.

When using 'python -c "some; cmd", the expected value for sys.argv would be either:
  [ ''] # sys.argv value in interactive mode -> sys.argv[ 0] == ''
or
  [ 'some; cmd'] # value of the '-c' option: -> sys.argv[ 0] == 'some; cmd' - this contains more information

In this case, lines 283-288 from main.c could just be deleted.

FG


----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=423728&group_id=5470