New submission from Tim McDonough <tmcdonoug...@gmail.com>:

I found an odd behavior that seems to be limited to Python 3.6.3. 
Python 3.6.3 command scripts seem to prefer wrapping in double quotes instead 
of single quotes.

Here is an example of the error.  

$ echo -n '{"A":"a"}' | python3 -c 'import sys,json; j=json.load(sys.stdin); 
print(j["A"])'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
NameError: name 'A' is not defined

# Swapping single and double quotes works as expected.
#
$ echo -n '{"A":"a"}' | python3 -c "import sys,json; j=json.load(sys.stdin); 
print(j['A'])"
a

# Executing the original, failing script against python 2.6.6 works.
#
$ echo -n '{"A":"a"}' | python2 -c 'import sys,json; j=json.load(sys.stdin); 
print(j["A"])'
a

The failing environment is:
$ bash --version
GNU bash, version 4.1.2(2)-release (x86_64-redhat-linux-gnu)
$ gcc --version
gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-23)

These python versions also seem to work fine: 2.6.6, 2.7.9, 3.5.1, and 3.5.2.
Assigning the script to an environment variable follows the single/double quote 
issue. For example, this fails:

$ export python_script='import sys,json; j=json.load(sys.stdin); print(j["A"])'
$ echo -n '{"A": "a"}' | python3 -c "${python_script}"

This would be a good unit test candidate if not already present.

----------
components: Tests
messages: 326916
nosy: Tim McDonough
priority: normal
severity: normal
status: open
title: Python 3.6.3 command script wrapped in single quotes produces NameError: 
name 'A' is not defined
type: behavior
versions: Python 3.6

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue34874>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to