B
Bengt Richter
D'oh ;-/This is the equivalent of:
class Record:
pass
rec = Record()
Not thinking.
the foo in the print line isn't looked for until foo is executing,That is, the whole line after the : is interpreted as the body of the
class. The name Record is not defined within its body, hence the
NameError.
Another [sort-of related] question: why does the following not produce
a NameError for "foo"?
def foo(): print foo
foo()
by which time foo is bound. In contrast to the body of the class definition,
which executes right away to create the contents of the class dict etc.,
so there the class name is not yet bound.
Regards,
Bengt Richter