Jython - variables are stored somehow

nmin at freenet.de nmin at freenet.de
Thu Aug 9 14:30:00 CEST 2007


Hi,

I'm using Jython in combination with java.

I wrote a jython skript, which calls a function from another jython
module called library.py.

So, executing the function genData() in skript .py runs without
problem but if I execute the same function again, the data from the
first run is stored somehow and is added to the new data.

So, if you look at the result:
#1 in DatenTypen.py return an empty list each time the program runs.
Ok ... clear so far
#2 in library.py returns an empty list, when the program runs for the
first time ... but when the function is
called again, the list contains an element. Each time you call the
function again, one element is added!
Why??  out.abschnitte should be the same as printed in #1 or not?

Here is the code:

skript.py
======
from library import *

def genData():

 
out=DMS_sendFiles_ein_Abschnitt([["testdata1.test","testdata2.test","testdata3.test"]])

    return out

library.py
=======
from DatenTypen import AusgangsDatenDeichMonitor
from DatenTypen import DMS_Abschnitt
from DatenTypen import DMS_GeoData
from DatenTypen import DMS_GeoDataFile

def DMS_sendFiles_ein_Abschnitt(filelist):

    out=AusgangsDatenDeichMonitor()

    print "out.abschnitte: "+str(out.abschnitte) #2

    abschnitt=DMS_Abschnitt()

    for f in filelist:
        data=DMS_GeoData()

        for layer in f:

            datalayer=DMS_GeoDataFile()

            datalayer.dateiname=layer

            datalayer.dateiinhalt="TEST"

            data.layerFiles.append(datalayer)

        abschnitt.bildSequenze.append(data)

    out.abschnitte.append(abschnitt)

    return out

DatenTypen.py
===========

class AusgangsDatenDeichMonitor:

    abschnitte=[]

    def __init__(self):
        abschnitte=[]
        print "Abschnitt in DatenTypen: "+str(abschnitte) #1

class DMS_Abschnitt:

    bildSequenze=[]

    def __init__(self):
        abschnittsNummer=0
        bildSequenze=[]

class DMS_GeoData:

    layerFiles=[]

    def __init__(self):
        layerFiles=[]

class DMS_GeoDataFile:

    dateiinhalt="dateiinhalt"

    dateiname="dateiname"

    zipped=False

    def __init__(self):
        dateiinhalt="dateiinhalt"
        dateiname="dateiname"
        zipped=False

So, I read about deleting Instances with "del" ... but it does not
work at all.

Any Ideas?

Thanks  in advance

Simon




More information about the Python-list mailing list