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: attempt to access sys.argv when it doesn\'t exist
Type: Stage:
Components: Library (Lib) Versions: Python 2.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: georg.brandl, georg.brandl, ngrover, nnorwitz, nobody, vimboss
Priority: normal Keywords:

Created on 2003-11-10 10:56 by vimboss, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
diff vimboss, 2003-11-10 10:56 patch for warnings.py
Messages (6)
msg18953 - (view) Author: Bram Moolenaar (vimboss) Date: 2003-11-10 10:56
When using Python as an extension to another program,
giving a warning message attempts to access sys.argv
while it doesn't exist.

The problem can be reproduced with Vim when compiled
with Python 2.3.  Use these two commands:
    :py import sys
    :py print sys.maxint + 1

The problem is caused by the warnings module.  In line
53 it accesses sys.argv[0], but for an embedded
interpreter this doesn't exist.

The suggested fix does an explicit test for the
existence of sys.argv.  That seems to be the cleanest
solution to me.

This problem also existed in Python 2.2.  I didn't try
other versions.
msg18954 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2003-11-10 15:02
Logged In: YES 
user_id=33168

Just to provide a reference, 839200 was a duplicate of this
report.  I closed 839200.
msg18955 - (view) Author: Nobody/Anonymous (nobody) Date: 2003-11-19 05:22
Logged In: NO 

Much simplier test:

>>> import sys
>>> del sys.argv
>>> sys.maxint+1
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "D:\development\python22\lib\warnings.py", line 38,
in warn
    filename = sys.argv[0]
AttributeError: 'module' object has no attribute 'argv'
msg18956 - (view) Author: Nobody/Anonymous (nobody) Date: 2003-11-19 05:23
Logged In: NO 

Much simplier test:

>>> import sys
>>> del sys.argv
>>> sys.maxint+1
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "D:\development\python22\lib\warnings.py", line 38,
in warn
    filename = sys.argv[0]
AttributeError: 'module' object has no attribute 'argv'
msg18957 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2005-06-26 22:55
Logged In: YES 
user_id=1188172

Thanks for the report; this is fixed as of Lib/warnings.py
r1.27, r1.24.2.2.
msg18958 - (view) Author: Nishkar Grover (ngrover) Date: 2007-08-22 01:29
In addition to catching AttributeError in case sys.argv doesn't exist, this should also catch IndexError and TypeError in case sys.argv is an empty list or it is not even a list at all.
History
Date User Action Args
2022-04-11 14:56:01adminsetgithub: 39528
2003-11-10 10:56:09vimbosscreate