I have the following script in a file [simplified from the actual case]
# /tmp/test.py
from collections import defaultdict
a = defaultdict(lambda: defaultdict(list))
a[1][1].append(1)
print(a)
When I execute these in the ptpython REPL, everything works fine - prints out
defaultdict(<function <lambda> at 0x7f8ecc06a488>, {'1': defaultdict(<class 'list'>, {1: [1]})})
When I try to execute this script from the command line as
ptpython /tmp/test.py
an error is thrown:
Traceback (most recent call last):
File "/home/danny/ciq/env36/bin/ptpython", line 11, in <module>
sys.exit(run())
File "/home/danny/ciq/env36/lib/python3.6/site-packages/ptpython/entry_points/run_ptpython.py", line 58, in run
six.exec_(code)
File "/tmp/test.py", line 3, in <module>
a['1'][1].append(1)
File "/tmp/test.py", line 2, in <lambda>
a = defaultdict(lambda: defaultdict(list))
NameError: name 'defaultdict' is not defined
I am in a virtual environment (though leaving my virtual environment doesn't change the error). I am using ptpython version 2.0.6, installed with pip, on ubuntu 18.04, with python 3.6.3
When I run this file with python /tmp/test.py , bpython /tmp/test.py, and ipython /tmp/test.py, each of them correctly prints out my defaultdict - only ptpython throws this NameError
Let me know if any further information would be helpful!
I have the following script in a file [simplified from the actual case]
When I execute these in the ptpython REPL, everything works fine - prints out
defaultdict(<function <lambda> at 0x7f8ecc06a488>, {'1': defaultdict(<class 'list'>, {1: [1]})})
When I try to execute this script from the command line as
ptpython /tmp/test.py
an error is thrown:
I am in a virtual environment (though leaving my virtual environment doesn't change the error). I am using ptpython version 2.0.6, installed with pip, on ubuntu 18.04, with python 3.6.3
When I run this file with
python /tmp/test.py
,bpython /tmp/test.py
, andipython /tmp/test.py
, each of them correctly prints out my defaultdict - only ptpython throws this NameErrorLet me know if any further information would be helpful!