NameError in list comprehension when using embed
See original GitHub issueThis used to work, and stopped working somewhere around six months to a year ago.
In [51]: from os.path import getsize
In [52]: ziplen = dict((_, getsize(_)) for _ in zips)
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
/nrg1/tools/datateam/packages/nuance.com/nvc4-pipeline-utils/nvc4qless.py in <module>()
----> 1 ziplen = dict((_, getsize(_)) for _ in zips)
/nrg1/tools/datateam/packages/nuance.com/nvc4-pipeline-utils/nvc4qless.py in <genexpr>((_,))
----> 1 ziplen = dict((_, getsize(_)) for _ in zips)
NameError: global name 'getsize' is not defined
zips
is a list of paths, but this happens for list comprehension all over the place. Not sure what local/global namespace the list comprehension doesn’t get.
Issue Analytics
- State:
- Created 8 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Why does list comprehension closure throw `NameError` in ...
A list comprehension in a class definition can reference other class level variables in both python 2 and 3 as part of the...
Read more >Comprehensions - The Conservative Python 3 Porting Guide
List comprehensions, a shortcut for creating lists, have been in Python since version 2.0 ... as running the code under Python 3 will...
Read more >list comprehensions don't see local variables in pdb in python3
The NameError exception occuring on a generator expression referencing a local variable when the generator is called within exec() is the object ......
Read more >List comprehension - NameError: name '_[1]' is not defined ?
mini-template, i'd like to embed other expressions for the % operator, and that may of course also be list comprehensions. Thanks!
Read more >Can you embed a try in a Python list comprehension?
No, you can not do this directly in a list comprehension. You must factor the try/except logic out into a separate function, and...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ok,
start_ipython(argv=[])
is more elegant.Deep diving in the code yields this:
That way, globals and locals are the same object, like in the normal shell.