> Hi, > > I'm having difficulty understanding why the following code doesn't work: > > > getfr.py > #import pymetar > # > #class wReport: > # def __init__(self,metarcode="CYYC"): #weather for calgary INTL > # self.METARCODE=metarcode > # rf=pymetar.ReportFetcher(self.METARCODE) > # rep=rf.FetchReport() > # pr=rp.ParseReport(rep) > # def getRep() > # return pr.getFullReport > > #>>> import getfr > > #>>> w = getfr.wReport() > > #Traceback (most recent call last): > > # File "<stdin>", line 1, in ? > > # File "getfr.py", line 8, in __init__ > > # pr=rp.ParseReport(rep) > > #NameError: global name 'rp' is not defined
I would also suggest, along side Kent's suggestion, that you rewrite two things. 1) pr = rp.ParseReport(rep) as self.pr = rp.ParseReport(rep) 2) def getRep(): as def getRep(self): to make it a method of the class Obviously, this will not fix your problem, but it makes it neater and less error prone in the future. To fix your problem, I refered to Kent... I'm done, Jacob _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor