Reputation: 165
If I have class Foo...
class Foo(object):
bar = True
does calling Foo.bar
instantiate an object of type Foo that gets immediately garbage collected?
would I have to include ()
in between Foo and bar to create an instance of that type?
if I do need the parentheses, what method do they call? __init__()
?
Upvotes: 1
Views: 32
Reputation: 362647
does calling Foo.bar instantiate an object of type Foo that gets immediately garbage collected?
No. You've defined Foo.bar
here as a class attribute, not an instance attribute.
would I have to include () in between Foo and bar to create an instance of that type?
Yes, calling Foo()
is the correct syntax to create a Foo
object.
if I do need the parentheses, what method do they call?
__init__()
?
First __new__
will be called (perhaps from the superclass object
) which actually creates the new object, and then __init__
will be called which initialises the already existing object.
Upvotes: 1