I've got two classes in two different modules:
animal.py
monkey.py
animal.py:
import json
class Animal(object):
pass
monkey:
import animal
class Monkey(animal.Animal):
def __init__(self):
super(Monkey, self).__init__()
# Do some json stuff...
When I try to instantiate a Monkey
, I get a
NameError: global name 'json' is not defined
But I'm importing json
in the defining module of the super class, so why wouldn't it be loaded?
It is loaded, but its name is not available in the scope of monkey.py
.
You could type animal.json
to get at it (but why would you), or just type
import json
in monkey.py
as well. Python will ensure that the module is not loaded twice.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With