[SciPy-user] accessing a class's code
ryanlists at gmail.com
Wed Apr 19 13:04:42 CDT 2006
Thanks Doug. I think that is a great start.
Not to justify myself, but I have gotten like 10 responses on
comp.lang.python mainly asking why I would want to do such a thing or
assuming I am an idiot.
I got one response here and it was very helpful.
On 4/19/06, LATORNELL, Doug <Doug.LATORNELL at mdsinc.com> wrote:
> I think the inspect module
> (http://docs.python.org/lib/module-inspect.html) in the standard library
> might enable you to do what you want. I've never used inspect (just
> read its docs when they caught my eye a couple of weeks ago), nor done
> what you describe though, so I can't promise that I'm not sending you on
> a wild goose chase :-)
> > -----Original Message-----
> > From: scipy-user-bounces at scipy.net
> > [mailto:scipy-user-bounces at scipy.net] On Behalf Of Ryan Krauss
> > Sent: April 19, 2006 08:40
> > To: SciPy Users List
> > Subject: [SciPy-user] accessing a class's code
> > I don't have the best of luck with comp.lang.python and I get
> > great results from this list. So, I am mildly sorry about
> > the general python question and the double post.
> > I have a set of Python classes that represent elements in a
> > structural model for vibration modeling (sort of like FEA).
> > Some of the parameters of the model are initially unknown and
> > I do some system identification to determine the parameters.
> > After I determine these unknown parameters, I would like to
> > substitute them back into the model and save the model as a
> > new python class. To do this, I think each element needs to
> > be able to read in the code for its __init__ method, make the
> > substitutions and then write the new __init__ method to a
> > file defining a new class with the now known parameters.
> > Is there a way for a Python instance to access its own code
> > (especially the __init__ method)? And if there is, is there a clean
> > way to write the modified code back to a file? I assume that if I
> > can get the code as a list of strings, I can output it to a
> > file easily enough.
> > I am tempted to just read in the code and write a little
> > Python script to parse it to get me the __init__ methods, but
> > that seems like reinventing the wheel.
> > I don't just want to read and write a vector of coefficients
> > because after I have identified the unknown structural
> > parameters, I will use the model for control design and there
> > will be a new set of unknown control parameters.
> > Thanks,
> > Ryan
> > _______________________________________________
> > SciPy-user mailing list
> > SciPy-user at scipy.net
> > http://www.scipy.net/mailman/listinfo/scipy-user
> This email and any files transmitted with it may contain privileged or confidential information and may be read or used only by the intended recipient. If you are not the intended recipient of the email or any of its attachments, please be advised that you have received this email in error and any use, dissemination, distribution, forwarding, printing or copying of this email or any attached files is strictly prohibited. If you have received this email in error, please immediately purge it and all attachments and notify the sender by reply email or contact the sender at the number listed.
> SciPy-user mailing list
> SciPy-user at scipy.net
More information about the SciPy-user