Diez B. Roggisch wrote:
John wrote:

I'm okay with init, but it seems to me that enter is redundant since it
appears that anything you want to execute in enter can be done in init.

About what are you talking?
Diez

Do you mean __init__ and __enter__?

They are used for two completely different purpose. __init__ is used to initialize an object when they've just been created. __enter__ is called when an object enters a Context Manager (i.e. with statement)

Example, when opening a file:

# this calls file.__init__
f = open('foo.bar')

# some codes...

# this calls file.__enter__
with f:
    pass

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to