[Tutor] is it possible to create and amend classes during run-time?
Bjorn Madsen
bjorn.madsen at operationsresearchgroup.com
Sat May 5 00:07:30 CEST 2012
Sorry I didn't get back earlier. But in short: Thank you!
Kind Regards,
Bjorn
On 3 May 2012 00:01, Alan Gauld <alan.gauld at btinternet.com> wrote:
> Does anyone know if it is possible during run-time to:
>>> a) add attributes to classes, which will unknown at program start, but
>>> "emerge" later whilst the program is running?
>>>
>>
> Yes, but its not very useful since the rest of your code won't know how to
> access those attributes. There are ways around that (getattr() etc)
> but in general it's a bad design pattern that should be avoided.
>
> But Python is an interpreted language so anything you can do in a script
> file can also be done at runtime.
>
>
> b) add subclasses to class (also during runtime)
>>>
>>
> I'm not sure what you mean, but I'm guessing you are asking if you can
> subclass an existing class. That is create a new class, and again the
> answer is yes.
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
>
> ______________________________**_________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/**mailman/listinfo/tutor<http://mail.python.org/mailman/listinfo/tutor>
>
--
Bjorn Madsen
*Researcher Complex Systems Research*
Ph.: (+44) 0 7792 030 720 Ph.2: (+44) 0 1767 220 828
bjorn.madsen at operationsresearchgroup.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120504/73e8375b/attachment.html>
More information about the Tutor
mailing list