| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • Finally, you can manage your Google Docs, uploads, and email attachments (plus Dropbox and Slack files) in one convenient place. Claim a free account, and in less than 2 minutes, Dokkio (from the makers of PBworks) can automatically organize your content for you.

View
 

CreateObject

Page history last edited by PBworks 12 years, 5 months ago

explain __int__

 

obj3 = MyClass()

 

(it's the () that creates the object, not the =)

 

_ _new__ is the constructor: it creates the instance and returns it (overriding: advanced topic)

 

Along the way, it calls _ _init__ on the *already-created* instance, to

ask it to initialise itself ready for use. So, _ _init__ is an

"initialiser" for the instance, used often. Rarely you override _ _new__, but customizing _ _init__ is common: http://www.python.org/doc/ref/customization.html

 

obj = mytype.__new__(*args, **kwds)

if isinstance(obj, mytype):

mytype.__init__(obj, *args, **kwds)

return obj

 

Nevertheless, _ _init__ doesn't construct anything. You can even call

it to reinitialize an existing object.

 

Also, how can a constructor require 'self' as an argument...?

_ _init__(self, ...)

 

If the _ _init__ function is called by the constructor it cannot return a

value. However if called as a normal function, it can return a value.

_ _init__ is just a function that gets called during the construction

Comments (0)

You don't have permission to comment on this page.