This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Python 3 doesn't register script arguments
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.1
process
Status: closed Resolution: duplicate
Dependencies: Superseder: sys.argv contains only scriptname
View: 7936
Assigned To: Nosy List: Sworddragon, eric.araujo, loewis, mark.dickinson
Priority: normal Keywords:

Created on 2010-06-12 20:10 by Sworddragon, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (13)
msg107690 - (view) Author: (Sworddragon) Date: 2010-06-12 20:10
Python 3.1.2 hasn't any arguments except the file name in sys.argv[0]. For example: build.py test
sys.argv[1] will be empty. I tried even the first example from the documentation 15.4 (optparse) but the filename is None. In Python 2.6.5 all is working fine.
msg107692 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-06-12 20:20
It's not entirely clear to me what issue you're reporting here:  could you provide a short example script that exhibits the problem, and list the exact steps necessary to reproduce, along with actual and expected results?
msg107696 - (view) Author: (Sworddragon) Date: 2010-06-12 20:35
Examplescript test.py:

import sys
print(sys.argv[1])


Call this script now with an argument, for exmaple: test.py 1234
I expect to see the string 1234 in the console but Python 3 says "IndexError: list index out of range". With Python 2.6.5 I be able to see the correct string 1234.
msg107700 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-06-12 20:48
Can’t reproduce here:
$ python3.1 -c "import sys; print(sys.argv[1])" 1234
1234
$ python3.1 --version
Python 3.1.2
msg107701 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-06-12 20:49
Hmm.  I don't see any difference between the two here (OS X 10.6).  What platform are you on, and where did your copy of Python 3.1.2 come from?

newton:~ dickinsm$ cat test.py
import sys
print(sys.argv[1])
newton:~ dickinsm$ python3.1 test.py 1234
1234
newton:~ dickinsm$ python2.6 test.py 1234
1234
newton:~ dickinsm$ python3.1
Python 3.1.2 (r312:79147, May 18 2010, 17:21:15) 
[GCC 4.2.1 (Apple Inc. build 5659)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 
newton:~ dickinsm$ python2.6
Python 2.6.5 (r265:79063, May 18 2010, 17:12:15) 
[GCC 4.2.1 (Apple Inc. build 5659)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
msg107702 - (view) Author: (Sworddragon) Date: 2010-06-12 20:52
I'm using Windows XP Professional SP3. I downloaded Python 3.1.2 from this site. Even Python 3.0.1 hasn't worked.
msg107703 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-06-12 20:55
3.0 should not be used and does not get fixes.

Can you try downloading Python again and testing?

P.S. please do not change the component; Lib means “Python files under Lib/ in the source checkout”, but sys is a module built by the interpreter core.
msg107704 - (view) Author: (Sworddragon) Date: 2010-06-12 21:03
I have already installed Python 3.1.2 a second time. I have selected during the installation that the files shall be compiled into bytecode.
msg107706 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-06-12 21:35
I'm failing to reproduce this on Windows 7, too.

It sounds as though you're starting the python script without an explict 'python'.  What are your filetype associations for python scripts?

i.e., what's the result of typing 'assoc py' at a console prompt?
And what's the result of the 'ftype' command for the above?

Just for reference, I get:

>assoc.py
.py=Python.File

>ftype Python.File
Python.File=C:\Python31\python.exe "%1" %*
msg107707 - (view) Author: (Sworddragon) Date: 2010-06-12 21:51
assoc .py
.py=Python.File

I tried this now with Ubuntu and Python 3.1.2 and all works fine. But under Windows XP it doesn't work.
msg107708 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-06-12 21:56
Okay, thanks.  What does

ftype Python.File

give?
msg107709 - (view) Author: (Sworddragon) Date: 2010-06-12 22:09
ftype Python.File
Python.File="E:\Python31\python.exe" "%1" %*
msg107710 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-06-12 22:23
I've just found issue #7936, which looks like the same problem.  I'm going to close this issue as a duplicate of that one;  further discussion should be moved there.
History
Date User Action Args
2022-04-11 14:57:02adminsetgithub: 53230
2010-06-12 22:23:15mark.dickinsonsetstatus: open -> closed
resolution: duplicate
superseder: sys.argv contains only scriptname
messages: + msg107710
2010-06-12 22:09:46Sworddragonsetmessages: + msg107709
2010-06-12 21:56:37mark.dickinsonsetmessages: + msg107708
2010-06-12 21:51:30Sworddragonsetmessages: + msg107707
2010-06-12 21:35:27mark.dickinsonsetmessages: + msg107706
2010-06-12 21:22:29pitrousetnosy: + loewis
2010-06-12 21:03:43Sworddragonsetmessages: + msg107704
components: + Library (Lib), - Interpreter Core
2010-06-12 20:55:01eric.araujosetmessages: + msg107703
components: + Interpreter Core, - Library (Lib)
2010-06-12 20:52:50Sworddragonsetmessages: + msg107702
components: + Library (Lib), - Interpreter Core
2010-06-12 20:49:36mark.dickinsonsetmessages: + msg107701
2010-06-12 20:48:48eric.araujosetnosy: + eric.araujo
messages: + msg107700
components: + Interpreter Core, - Library (Lib)
2010-06-12 20:35:14Sworddragonsetmessages: + msg107696
2010-06-12 20:20:01mark.dickinsonsetnosy: + mark.dickinson
messages: + msg107692
2010-06-12 20:10:21Sworddragoncreate