[Python-talk] Speaking of oops. How to call a method in another class in another file?
bruce.labitt at autoliv.com
bruce.labitt at autoliv.com
Tue Jul 28 16:05:48 EDT 2009
python-talk-bounces at dlslug.org wrote on 07/28/2009 02:49:30 PM:
> bruce.labitt at autoliv.com wrote:
> > I'm plodding along with wxpython. I mostly have the graphic part set
up.
> > Now I am trying to connect the display to bits of my program. The
first
> > bit is to plot an existing data file. I used filepicker to get the
full
> > file name. I don't quite understand how to invoke/use one of the
methods
> > that I created in the class Xambig.
> >
> > Xambig is in the file genwave.py. Inside of Xambig is a method named
> > plotMe.
> >
> (snip)
>
> > if ( plot =="Plot existing"):
> > p = genwave.Xambig()
> > plotme(p, filepath, myrange) ???
> >
> >
>
> The call would be:
>
> p.plotme(filepath, myrange)
>
> When you call it that way, the object itself ('p' in this case) is
> implicitly passed as the first ('self') parameter of the method.
>
> Larry
>
That was my first approach. I got the following error
AttributeError: Xambig instance has no attribute 'plotme'
What do I need to do in the __init__ part of the class? Right now it is
empty.
Do I need to do something like
class Xambig:
def __init__(self):
# initialization stuff here... then
myfile = "ambig.dat"
myrange = 200.00
self.plotme = plotMe(myfile, myrange)
def plotMe(self, fileName, myRange):
"""plot all kinds of stuff"""
Then
if ( plot=="Plot existing" ):
p = genwave.Xambig()
p.plotme( myfile, myrange )
-Bruce
<snip>
> _______________________________________________
> Python-talk mailing list
> Python-talk at dlslug.org
> http://dlslug.org/mailman/listinfo/python-talk
******************************
Neither the footer nor anything else in this E-mail is intended to or constitutes an <br>electronic signature and/or legally binding agreement in the absence of an <br>express statement or Autoliv policy and/or procedure to the contrary.<br>This E-mail and any attachments hereto are Autoliv property and may contain legally <br>privileged, confidential and/or proprietary information.<br>The recipient of this E-mail is prohibited from distributing, copying, forwarding or in any way <br>disseminating any material contained within this E-mail without prior written <br>permission from the author. If you receive this E-mail in error, please <br>immediately notify the author and delete this E-mail. Autoliv disclaims all <br>responsibility and liability for the consequences of any person who fails to <br>abide by the terms herein. <br>
******************************
More information about the Python-talk
mailing list