Need help to pass self.count to other classes.

Peter Otten __peter__ at web.de
Fri Jan 8 19:10:37 CET 2010


Steve Holden wrote:

> Steven D'Aprano wrote:
> [... points out my misapprehension ...]
>> 
>>>>> kbi = kbInterface()
>>>>> sys.ps1 = kbi.prompt1
>> <bound method kbInterface.prompt1 of <__main__.kbInterface object at
>> 0xb7cbd52c>>print "Hello"
>> Hello
>> <bound method kbInterface.prompt1 of <__main__.kbInterface object at
>> 0xb7cbd52c>>
>> 
> Right, this is expert mode ...

Here's a way to turn expert mode into something less advanced:

>>> import sys
>>> def expert_mode():
...     return "for newbies ;) "
...
>>> sys.ps1 = expert_mode
<function expert_mode at 0x7f498b9735f0>class Str:
...     def __init__(self, f): self.f = f
...     def __str__(self): return self.f()
...
<function expert_mode at 0x7f498b9735f0>sys.ps1 = Str(expert_mode)
for newbies ;)

Peter



More information about the Python-list mailing list