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@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor