New submission from Pedro <[email protected]>:
Embedded Python interpreters, such as Boost.Python, do not have sys.argv
available. (sys itself works fine.) This causes the interpreter to crash with
the following exception when you try to access argv:
AttributeError: 'module' object has no attribute 'argv'
I'm not sure how closely related this is to #15577 or PEP 432. A simple
workaround is to manually assign a list with an empty string to argv, as
suggested by https://github.com/google/oauth2client/issues/642. However, the
documentation for the sys module makes no mention of this special case for
argv, and the line at the top that says "It is always available" can easily be
interpreted to mean that *all* of sys's attributes will always be available. I
suggest adding the following to the documentation for sys.argv:
========
Since `argv` contains the list of **command line** arguments passed to the
Python interpreter, `argv` is not available within embedded interpreters, and
scripts that run in embedded environments will raise an `AttributeError` when
they attempt to access `argv`. As a workaround, assign a list with an empty
string manually:
```
import sys
if not hasattr(sys, 'argv'):
sys.argv = ['']
```
----------
assignee: docs@python
components: Documentation
messages: 310105
nosy: docs@python, pgacv2
priority: normal
severity: normal
status: open
title: sys.argv documentation should include caveat for embedded environments
type: enhancement
versions: Python 2.7, Python 3.4, Python 3.5, Python 3.6, Python 3.7
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue32573>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com