🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.free.newsservers
Article #100212

Self in Interactive Interpreter

#100212
From: 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,
Technical Details
Message-ID: <82f7102e-c2f9-4e9a-a26a-a6e2ba5453da@i12g2000prf.googlegroups.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-alt.free.newsservers.20150605.mbox.gz!number1.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!postnews.google.com!i12g2000prf.googlegroups.com!not-for-mail

Show Full Headers
Complete Article Headers
Message-ID: <82f7102e-c2f9-4e9a-a26a-a6e2ba5453da@i12g2000prf.googlegroups.com>
Subject: Self in Interactive Interpreter
Date: Fri, 04 Apr 2008 05:56:41 +0000
From: kj7ny <kj7ny@nakore.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-alt.free.newsservers.20150605.mbox.gz!number1.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!postnews.google.com!i12g2000prf.googlegroups.com!not-for-mail
Newsgroups: alt.free.newsservers
Organization: http://groups.google.com
Lines: 36
NNTP-Posting-Host: 72.87.3.186
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-Trace: posting.google.com 1207288602 9460 127.0.0.1 (4 Apr 2008 05:56:42 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Fri, 4 Apr 2008 05:56:42 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: i12g2000prf.googlegroups.com; posting-host=72.87.3.186;
 posting-account=8gyeKAoAAABAPjn0b548Jv-y1pSGBscf
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.1)
 Gecko/20060601 Firefox/2.0.0.1 (Ubuntu-edgy),gzip(gfe),gzip(gfe)