What is the difference between init and enter?

685 views
Skip to first unread message

John

unread,
May 26, 2009, 7:42:01 AM5/26/09
to
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.

Diez B. Roggisch

unread,
May 26, 2009, 7:52:41 AM5/26/09
to
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

Lie Ryan

unread,
May 26, 2009, 9:23:43 AM5/26/09
to

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

Gary Herron

unread,
May 26, 2009, 10:48:27 AM5/26/09
to pytho...@python.org

The proper response to a question like this has to be
http://www.catb.org/~esr/faqs/smart-questions.html
as anything else is complete guesswork.

Gary Herron

Carl Banks

unread,
May 26, 2009, 9:26:17 PM5/26/09
to

Is there a Cliff's Notes version of this?

I may be a cynic but I would think the people who ask bad questions
are the same sort of people who won't have the patience to sit though
this behemoth of an essay.

And I may be a romantic but I would think most people who post this
are really trying to be helpful and not just saying, "Out of my midst,
vile newbie, until thou hearkenst unto the sacred words".

So, it would seem that a summary (with citations) of the essay would
be useful.


Carl Banks

Martin P. Hellwig

unread,
May 26, 2009, 9:54:36 PM5/26/09
to

I can do a quick one albeit without citation:

- Have you googled/searched?
- No really, have you?
- Are you really, really sure?

- So what did you 'search for|tried before' which didn't returned a
result you can work with?
- What does that tell you about yourself?
- So what do _you_ think _you_ should do first to solve _your_ problem?

- Okay, fair enough, tell me your problem, give me some background, give
me some examples, skip the waffling, be polite I am here out of my own
good will.

A: See you haven't searched properly | Hmm intriguing | Seems like a
bug, contact the author

--
MPH
http://blog.dcuktec.com
'If consumed, best digested with added seasoning to own preference.'

Martin P. Hellwig

unread,
May 26, 2009, 10:03:08 PM5/26/09
to
Martin P. Hellwig wrote:
<cut see previous>

> I can do a quick one albeit without citation:
>
> - Have you googled/searched?
> - No really, have you?
> - Are you really, really sure?
>
> - So what did you 'search for|tried before' which didn't returned a
> result you can work with?
> - What does that tell you about yourself?
> - So what do _you_ think _you_ should do first to solve _your_ problem?
>
> - Okay, fair enough, tell me your problem, give me some background, give
> me some examples, skip the waffling, be polite I am here out of my own
> good will.
>
> A: See you haven't searched properly | Hmm intriguing | Seems like a
> bug, contact the author
>

Oh I forgot:
- Be complete, don't forget essential things
- Write simple sentences, I don't want to guess the meaning of your epistle
- Use a spell checker
- It doesn't hurt to reread before hitting the send button

Ben Finney

unread,
May 27, 2009, 3:07:25 AM5/27/09
to
Carl Banks <pavlove...@gmail.com> writes:

> On May 26, 7:48 am, Gary Herron <gher...@islandtraining.com> wrote:
> > The proper response to a question like this has to be  
> >  http://www.catb.org/~esr/faqs/smart-questions.html as anything else
> > is complete guesswork.
>
> Is there a Cliff's Notes version of this?
>
> I may be a cynic but I would think the people who ask bad questions
> are the same sort of people who won't have the patience to sit though
> this behemoth of an essay.

To the extent that's the case, then it benefits the community as a
filter, by making it easier to detect those who aren't going to read a
good essay on how to participate in a community of question-answerers.

On the other hand, I prefer to give questioners the benefit of the doubt
by not discounting the possibility that they *can* read and learn how to
improve the quality of their questions.

> And I may be a romantic but I would think most people who post this
> are really trying to be helpful and not just saying, "Out of my midst,
> vile newbie, until thou hearkenst unto the sacred words".

Posting a reference to the “asking questions the smart way” essay is,
at least most of the times I've seen it, an explicit effort to be
helpful to the questioner *and* to the community that bears the load of
finding out what the questioner needs answered — both in this instance,
and in any future instance when people who read that suggestion want to
ask other questions.

--
\ “When I wake up in the morning, I just can't get started until |
`\ I've had that first, piping hot pot of coffee. Oh, I've tried |
_o__) other enemas...” —Emo Philips |
Ben Finney

Aahz

unread,
May 30, 2009, 1:41:52 PM5/30/09
to
In article <960af9f3-c445-4d6d...@s28g2000vbp.googlegroups.com>,
Carl Banks <pavlove...@gmail.com> wrote:

>On May 26, 7:48=A0am, Gary Herron <gher...@islandtraining.com> wrote:
>>
>> The proper response to a question like this has to be
>> =A0 =A0http://www.catb.org/~esr/faqs/smart-questions.html

>> as anything else is complete guesswork.
>
>Is there a Cliff's Notes version of this?
>
>I may be a cynic but I would think the people who ask bad questions
>are the same sort of people who won't have the patience to sit though
>this behemoth of an essay.

Perhaps linking directly to this would help:

http://www.catb.org/~esr/faqs/smart-questions.html#before

The table of contents contains a good summary for actually asking
questions. Overall, I'm inclined to agree with people who argue that the
smart questions essay is a good filter; someone unwilling to put in the
work of reading and understanding it is also unwilling to put in the
effort to ask good questions. I mean, I re-read most of that essay once
every couple of years myself.
--
Aahz (aa...@pythoncraft.com) <*> http://www.pythoncraft.com/

my-python-code-runs-5x-faster-this-month-thanks-to-dumping-$2K-
on-a-new-machine-ly y'rs - tim

Reply all
Reply to author
Forward
0 new messages