🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: alt.free.newsservers
3 messages
3 total messages Started by kj7ny Fri, 04 Apr 2008 05:56
Self in Interactive Interpreter
#100212
Author: kj7ny
Date: Fri, 04 Apr 2008 05:56
36 lines
2464 bytes
Hope this hasn't been posted hundreds of times. I have never seen it
before, but could have missed it.

For years it has been a slight annoyance that every time I wanted to
test a snippet of code from a class by running it in the interactive
interpreter, I had to remove all of the self. instances from the
code.  After I got it working correctly, I had to put all the self.'s
back into the code to put it back into my class.

The other day my brain had a functional synapse and I realized I could
just start my interactive session with:

>>> class dummy:
>>>     def __init__(self):
>>>         pass
>>>
>>> self=dummy()

I could then just set up my test variables something like:

>>> self.x='Hello '
>>> self.y='World'

And I could then use class type code such as:

>>> print self.x, self.y

I no longer had to remove and then replace all of the self. notation
from my code snippets.

So far I haven't seen why I shouldn't to this.  I haven't had any
problems using it, but I haven't used it that much.  If there is a
good reason to NOT do it, let me know.  Otherwise I hope this helps
anyone who has been annoyed by the same thing.

Thanks,
Re: Self in Interactive Interpreter
#100213
Author: Tony
Date: Fri, 04 Apr 2008 05:59
45 lines
2400 bytes
Yes i was annoyed by the same thing just a few weeks ago.

kj7ny wrote:

> Hope this hasn't been posted hundreds of times. I have never seen it
> before, but could have missed it.
>
> For years it has been a slight annoyance that every time I wanted to
> test a snippet of code from a class by running it in the interactive
> interpreter, I had to remove all of the self. instances from the
> code.  After I got it working correctly, I had to put all the self.'s
> back into the code to put it back into my class.
>
> The other day my brain had a functional synapse and I realized I could
> just start my interactive session with:
>
> >>> class dummy:
> >>>     def __init__(self):
> >>>         pass
> >>>
> >>> self=dummy()
>
> I could then just set up my test variables something like:
>
> >>> self.x='Hello '
> >>> self.y='World'
>
> And I could then use class type code such as:
>
> >>> print self.x, self.y
>
> I no longer had to remove and then replace all of the self. notation
> from my code snippets.
>
> So far I haven't seen why I shouldn't to this.  I haven't had any
> problems using it, but I haven't used it that much.  If there is a
> good reason to NOT do it, let me know.  Otherwise I hope this helps
> anyone who has been annoyed by the same thing.
>
> Thanks,

--
Regards Tony... Making usenet better for everyone everyday

Re: Self in Interactive Interpreter
#100226
Author: kj7ny
Date: Fri, 04 Apr 2008 20:12
2 lines
1451 bytes
Hmmm.... I was 100% sure I had posted this in comp.lang.python.  How
did it end up here?
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads