Reputation: 2011
I am using the following iter chain, to generate a list -
from itertools import chain
from utils import my_func // custom function written that performs a function.
a = list(chain.from_iterable((u, my_func(u)) for u in MyCustomClass.objects.all()))
I expect that a list will be generated.
But then, I get the error - NameError: global name 'my_func' is not defined
What am I doing wrong?
Upvotes: 0
Views: 110
Reputation: 12986
If you are using Django/iPython there is a bug with Django: iPython is started with a different namespace, which could explain your problem.
You can try to use a different shell (base python
or bpython) or try to patch your Django installation. See this answer for more information.
Upvotes: 1
Reputation: 475
Try utils.func(), could be that the function is out of the current scope
Upvotes: 0