[Tutor] help -Global name xxxxxxxx is not definied.
leon zaat
zaatlob at hotmail.com
Thu Aug 9 15:09:44 CEST 2012
Thanks,
adding the self as suggested did the trick.
> To: tutor at python.org
> From: __peter__ at web.de
> Date: Thu, 9 Aug 2012 14:45:58 +0200
> Subject: Re: [Tutor] help -Global name xxxxxxxx is not definied.
>
> leon zaat wrote:
>
> > Hello everyone,
> >
> > Can anybody help me with this problem.
> > Ik have a program that i' am modifying.
> >
> > Ik build a function to export data to a csv file. I tried the functions
> > over different parts, that needed to be extracted. The parts on it self
> > worked fine. Now I put all parts in my function. Because there was a
> > sections that was all alike for the parts, i thought to put it in a second
> > function.
> >
> > This is the code I written:
>
> > # schrijven van de records
>
> > def schrijfExportRecord():
> > sql1="";
> ...
>
> > def ExportBestanden(self, event):
> > ofile=open(r'D:\bestanden\BAG\adrescoordinaten.csv', 'wb')
> ...
>
> > When i run the program i got the following message:
> > NameError: global name 'schrijfExportRecord' is not found
> >
> > What I am doing wrong and how can i fix it?
>
> Judging from the indentation and the 'self' argument the code you quote is
> inside a class, e. g.
>
> class Whatever:
> def schrijfExportRecord():
> ...
> def ExportBestanden(self, event):
> ...
>
> This layout makes shrijfExportRecord() a method and you have to
>
> (1) add a self argument: def schrijfExportRecord(self): ...
> (2) invoke it in other methods as self.schrijfExportRecord()
>
> Alternatively you can leave it as is and move it out of the class (don't
> forget to fix the indentation accordingly):
>
> def schrijfExportRecord():
> ...
>
> class Whatever:
> def ExportBestanden(self, event):
> ...
>
> By the way
>
> del wpl[:];
>
> is probably "cargo cult" (the code has no effect) because the list is
> garbage-collected at the end of the function anyway. Also, in Python you
> don't need to place a ';' at the end of a statement unless you put multiple
> statements into one line (which is discouraged).
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120809/214e5f81/attachment.html>
More information about the Tutor
mailing list