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="";
        sql1="Select huisnummer, huisletter, huisnummertoevoeging, postcode, 
gerelateerdeopenbareruimte  from nummeraanduiding "
        sql1a= "where aanduidingrecordinactief<> 'J' and"
        hsql1=" einddatum > '" +  dag + "' and identificatie = '" + hoofdadres 
+ "'";
        sql1= sql1 + sql1a + hsql1;
        num= database.select(sql1);
        for row in num:
            huisnummer=row[0];
            huisletter=row[1];
            huisnummertoevoeging=row[2];
            postcode=row[3];
            gerelateerdeopenbareruimte=row[4];
            sql2="Select openbareruimtenaam, gerelateerdewoonplaats  from 
openbareruimte where aanduidingrecordinactief<> 'J'"
            sql2= sql2 + "and  einddatum > '" +  dag + "' and identificatie = 
'" +  gerelateerdeopenbareruimte + "'";
            opn=database.select(sql2);
            for row in database.select(sql2):
                openbareruimtenaam=row[0];
                gerelateerdewoonplaats=row[1];
                sql3="Select woonplaatsnaam  from woonplaats where 
aanduidingrecordinactief<> 'J'"
                sql3= sql3 + "and  einddatum > '" +  dag + "' and identificatie 
= '" +  gerelateerdewoonplaats + "'";
                wpl=database.select(sql3);
                for row in wpl:
                    woonplaatsnaam=row[0];
                    newrow=[identificatie, verblijfobjectgeometrie, huisnummer, 
huisletter, huisnummertoevoeging, postcode,openbareruimtenaam, woonplaatsnaam];
                    verblijfhoofd.writerow(newrow);

        del wpl[:];
        del opn[:];
        del num[:];
     
    
#--------------------------------------------------------------------------------------
    # Exporteer benodigde gegevens
    
#--------------------------------------------------------------------------------------
    def ExportBestanden(self, event):
        ofile=open(r'D:\bestanden\BAG\adrescoordinaten.csv', 'wb')
        verblijfhoofd = csv.writer(ofile, delimiter=',',
                         quotechar='"', quoting=csv.QUOTE_NONNUMERIC)
        dag=str(datetime.date.today());
        sql4="Select adresseerbaarobjectnevenadres.identificatie, 
adresseerbaarobjectnevenadres.nevenadres from adresseerbaarobjectnevenadres 
where aanduidingrecordinactief<> 'J' order by 
adresseerbaarobjectnevenadres.identificatie"
        neven= database.select(sql4);
        for row in neven: 
            nidentificatie=row[0];
            nevenadres=row[1];

            sql="Select identificatie, hoofdadres, ligplaatsgeometrie  from 
ligplaats where aanduidingrecordinactief<> 'J' and einddatum >'" + dag + "' and 
identificatie = '"+ nidentificatie + "'"
            lig= database.select(sql);
            for row in lig:
                hoofdadres=nevenadres;
                identificatie=row[0];
                verblijfobjectgeometrie=row[2];
                schrijfExportRecord(identificatie, hoofdadres, 
verblijfobjectgeometrie)
        sql="Select identificatie, hoofdadres, verblijfsobjectgeometrie  from 
verblijfsobject where aanduidingrecordinactief<> 'J' and einddatum >'" + dag + 
"' and identificatie = '"+ nidentificatie + "'"
            vbo= database.select(sql);
            for row in vbo:
                hoofdadres=row[1];
                identificatie=row[0];
                verblijfobjectgeometrie=row[2];
                schrijfExportRecord(identificatie, hoofdadres, 
verblijfobjectgeometrie)
            sql="Select identificatie, hoofdadres, standplaatsgeometrie  from 
standplaats where aanduidingrecordinactief<> 'J' and einddatum >'" + dag + "' 
and identificatie = '"+ nidentificatie + "'"
            stand= database.select(sql);
            for row in stand:
                hoofdadres=nevenadres;
                identificatie=row[0];
                verblijfobjectgeometrie=row[2];
                schrijfExportRecord(identificatie, hoofdadres, 
verblijfobjectgeometrie)
        del stand[:];
        del vbo[:];    
        del lig[:];
        del neven[:];
        sql="Select identificatie, hoofdadres, ligplaatsgeometrie  from 
ligplaats where aanduidingrecordinactief<> 'J' and einddatum >'" + dag + "'"
        lig= database.select(sql);
        for row in lig:
            hoofdadres=row[1];
            identificatie=row[0];
            verblijfobjectgeometrie=row[2];
            schrijfExportRecord()
        del lig[:];
        sql="Select identificatie, hoofdadres, standplaatsgeometrie  from 
standplaats where aanduidingrecordinactief<> 'J' and einddatum >'" + dag + "'"
        stand= database.select(sql);
        for row in stand:
            hoofdadres=row[1];
            identificatie=row[0];
            verblijfobjectgeometrie=row[2];
            schrijfExportRecord(identificatie, hoofdadres, 
verblijfobjectgeometrie)
        del stand[:];   
        counterVBO=2;
        identificatie='00000000';
        while 1 < counterVBO:
            hulpIdentificatie= identificatie;            
            sql="Select identificatie, hoofdadres, verblijfsobjectgeometrie  
from verblijfsobject where ";
            sql= sql + "identificatie > '" +  hulpIdentificatie ;
            sql= sql + "'  and aanduidingrecordinactief<> 'J' and einddatum >'" 
+ dag + "'  order by identificatie limit 100000";
            vbo= database.select(sql);
            if not vbo:
                break;
            else:
                for row in vbo:
                    hoofdadres=row[1];
                    identificatie=row[0];
                    verblijfobjectgeometrie=row[2];
                    sql1="";
                    sql1="Select huisnummer, huisletter, huisnummertoevoeging, 
postcode, gerelateerdeopenbareruimte  from nummeraanduiding "
                    sql1a= "where aanduidingrecordinactief<> 'J' and"
                    hsql1=" einddatum > '" +  dag + "' and identificatie = '" + 
hoofdadres + "'";
                    sql1= sql1 + sql1a + hsql1;
                    num= database.select(sql1);
                    for row in num:
                        huisnummer=row[0];
                        huisletter=row[1];
                        huisnummertoevoeging=row[2];
                        postcode=row[3];
                        gerelateerdeopenbareruimte=row[4];
                        sql2="Select openbareruimtenaam, gerelateerdewoonplaats 
 from openbareruimte where aanduidingrecordinactief<> 'J'"
                        sql2= sql2 + "and  einddatum > '" +  dag + "' and 
identificatie = '" +  gerelateerdeopenbareruimte + "'";
                        opn=database.select(sql2);
                        for row in database.select(sql2):
                            openbareruimtenaam=row[0];
                            gerelateerdewoonplaats=row[1];
                            sql3="Select woonplaatsnaam  from woonplaats where 
aanduidingrecordinactief<> 'J'"
                            sql3= sql3 + "and  einddatum > '" +  dag + "' and 
identificatie = '" +  gerelateerdewoonplaats + "'";
                            wpl=database.select(sql3);
                            for row in wpl:
                                woonplaatsnaam=row[0];
                                newrow=[identificatie, verblijfobjectgeometrie, 
huisnummer, huisletter, huisnummertoevoeging, postcode,openbareruimtenaam, 
woonplaatsnaam];
                                verblijfhoofd.writerow(newrow);
                           
                del vbo[:];
                ofile.close()

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

Reply via email to