On Wed, 4 Oct 2006, Daryl Tester wrote:
> Chris Foote wrote:
>
>> The voice peering project I'm working on has an embedded interpreter
>> running in a seperate thread in 'screen' sessions (using code.interact() )
>
> Reminding me of code.interact() brings up painful memories. :-) It's the
> second time where I've coded up something only to find out there was an
> equivalent method in the standard library (at the time of the quilter
> talk, my REPL was implemented using exec and eval, but I wasn't happy
> with it. Then I found HTTPREPL which pointed me in the appropriate
> direction). It annoys me, because when learning a language I make sure
> I go over the library in detail so I don't reinvent any unneccessary
> wheels.
hehehe... It's so easy to reinvent the wheel with Python anyway,
so it doesn't surprise me that everyone's written similar things :-)
HTTPREPL is very cool.. I stumbled onto it a couple of months back:
http://projects.amor.org/misc/wiki/HTTPREPL
>> It's a shame that it's not usable outside of reloading a module:
>>
>>>>> class C(object):
>> ... def method(self):
>> ... return '1st method version'
>> ...
>>>>> c = C()
>>>>> c.method()
>> '1st method version'
>>>>>
>>>>> def newmethod(self):
>> ... return '2nd method version'
>> ...
>>>>> C.method = newmethod
>>>>>
>>>>> c.method()
>> '2nd method version'
>>>>>
>>
>> i.e. existing object uses new version of method.
>
> I'd expect this, because the class that the instance refers
> to is being patched. Unfortunately the copy module doesn't
> appear to touch classes, but a possible workaround is to
> subclass C with the new method, then assign that to C.
>
> e.g. -
>
>>>> class C(object):
> ... def method(self):
> ... return '1st method version'
> ...
>>>> c = C()
>>>> c.method()
> '1st method version'
>>>> class C1(C):
> ... def method(self):
> ... return '2nd method version'
> ...
>>>> C = C1
>>>> c.method()
> '1st method version'
>>>> c1 = C()
>>>> c1.method()
> '2nd method version'
Cool - I didn't think of that :-)
> If a module is used there is no need to subclass the original
> class, as the new class is defined in what is effectively a
> new namespace (same name, but any existing instances hold
> references to the old namespace).
Very neat stuff.
--
Chris Foote <[EMAIL PROTECTED]>
Inetd Pty Ltd T/A HostExpress
Web: http://www.hostexpress.com.au
Blog: http://www.hostexpress.com.au/drupal/chris
Phone: (08) 8410 4566
_______________________________________________
sapug mailing list
[email protected]
http://mail.python.org/mailman/listinfo/sapug