Newbie Question

I

ishtar2020

Hi everyone

I'm sure this question is kinda stupid and has been answered a few
times before... but I need your help!

I'm writing a small application where the user can analyze some text
based on a set of changing conditions , and right now I'm stuck on a
point where I'd like to automatically generate new classes that operate
based on those user-defined conditions.

Is there a way in python to define a class in runtime? For instance,
can I define a class which extends another(that I have previously
defined in some module) , create some instance completely on the fly
and then add/redefine methods to it?

If affirmative, I've thought of a problem I would maybe have to face:
as the class has been defined by direct input to the python
interpreter, I could only create instances of it on the same session I
entered the definition(because it's not on a module I can load on
future uses) but not afterwards. Is there a way to keep that code?

Even more newbie paranoia: what would happen if I make that 'on the
fly" object persist via pickle? Where would Python find the code to
handle it once unpickled on another session (once again, i take that no
code with the definition of that instance would exist, as it was never
stored on a module).

Hope it wasn't too ridiculous an idea.

Thank you for your time, guys.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top