1 Nov 2002 01:01
Re: compute class name
Magnus Lycka <magnus <at> thinkware.se>
2002-11-01 00:01:41 GMT
2002-11-01 00:01:41 GMT
At 23:26 2002-10-31 +0100, Ulrich Wisser wrote: >I would like to create new object instances, but compute the >class name. Simple example > >name = "ExampleClass" >obj = name() >>> class X: ... def __init__(self): ... print "An X created" ... >>> name = 'X' >>> a = eval(name+'()') An X created >>> a <__main__.X instance at 0x00FA6908> I'm not entirely sure this is the best way to solve whatever problem you have though... Also note that: >>> class Odd: ... pass ... >>> class Even: ... pass ... >>> x = 3 >>> if x % 2: ... klass = Odd ... else:(Continue reading)
From the docstring:
>>> print time.sleep.__doc__
sleep(seconds)
Delay execution for a given number of seconds. The argument may be
a floating point number for subsecond precision.
>>>
> Also how would I tell the program to do something when the program is
exited
> by having the window closed to the computer shut down (anything with
the
> user manually typing 'quit' into the program)? I don't even know
where to
> begin with this.
>
Marc Andre Lemburg speaks to this here:
RSS Feed