[Python-talk] Speaking of oops. How to call a method in another class in another file?

Lloyd Kvam python at venix.com
Tue Jul 28 16:49:58 EDT 2009


On Tue, 2009-07-28 at 16:32 -0400, bruce.labitt at autoliv.com wrote:
> > > class Xambig:
> > >         def __init__(self):
> > >                 # initialization stuff here... then
> > >                 myfile = "ambig.dat"
> > >                 myrange = 200.00
> > >                 self.plotme = plotMe(myfile, myrange)
> > >
> > > 
> > 
> > Yes, you could do that sort of initialization stuff in __init__, if
> you wanted your object to default to having those values.
> > 
> > LArry
> > 
> 
> What if I don't want these defaults, but always want it passed from
> the 
> outside?
> If I comment out the initialization of myfile and myrange it dies.
> 

If __init__ is doing nothing, delete the whole method.  If that is not
relevant advice, give us a bit more info as to the cause of death
(syntax error? AttributeError?)

> 
> > >         def plotMe(self, fileName, myRange):
> > >                 """plot all kinds of stuff"""
> > >
> > > Then 
> > >
> > >                         if ( plot=="Plot existing" ):
> > >                                 p = genwave.Xambig()
> > >                                 p.plotme( myfile, myrange )

and that last line should be
	p.plotMe( myfile, myrange)
or maybe
	p.plotMe( 'ambig.dat', 200.0)

-- 
Lloyd Kvam
Venix Corp
DLSLUG/GNHLUG library
http://dlslug.org/library.html
http://www.librarything.com/catalog/dlslug
http://www.librarything.com/rsshtml/recent/dlslug
http://www.librarything.com/rss/recent/dlslug



More information about the Python-talk mailing list