473,405 Members | 2,444 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Jython - variables are stored somehow

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.t est"]])

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

Aug 9 '07 #1
3 1229
nm**@freenet.de schrieb:
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.t est"]])

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?
I think you should read a python-tutorial. The above code looks as if
you believe that

class Foo:
name = value

def __init__(self):
name = other_value

will create a class Foo, which then has instances with the property
"name", and that this is bound to other_value. Python isn't doing that.
name in the above example (and e.g. abschnitte in yours) are
class-attributes. That means that ALL instances of Foo share that name!!!

What you have to do is this:

class Foo:
def __init__(self, other_value):
self.name = other_value
please note the self in front of name!

Or, within your example:

class AusgangsDatenDeichMonitor:

def __init__(self):
self.abschnitte=[]
print "Abschnitt in DatenTypen: "+str(abschnitte) #1
There are a great many tutorials for python + OO out there - go read one
(or several).

Regards,

Diez
Aug 9 '07 #2
On Thu, 09 Aug 2007 05:30:00 -0700, nmin wrote:
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?
`out.abschnitte` is a *class* attribute so it is the same list on all
instances of that class.
class AusgangsDatenDeichMonitor:

abschnitte=[]
Everything on this level belongs to the class, so `abschnitte` is a class
attribute and shared by all instances of `AusgangsDatenDeichMonitor`.
def __init__(self):
abschnitte=[]
print "Abschnitt in DatenTypen: "+str(abschnitte) #1
Remove the class attribute and change the `__init__()` to:

def __init__(self):
self.abschnitte = list()
print "Abschnitt in DatenTypen: " + str(self.abschnitte)

So, I read about deleting Instances with "del" ... but it does not
work at all.
You can't delete objects with ``del``, just names or references to objects
in containers.

Ciao,
Marc 'BlackJack' Rintsch
Aug 9 '07 #3
works perfect ... thanks a lot!

Aug 14 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: John Taylor | last post by:
I have a jython program which uses both .py and .class (also 2 other standalone .jar files). Is it possible to create a .exe file with py2exe? When I try I get this error message: warning:...
1
by: Oten | last post by:
Ok I have looked all over the internet and I can't find what I am doing wrong or how I can do it right I am using windows xp Jython 2.1 I am trying to invoke the jython interpreter I have...
4
by: angel | last post by:
A java runtime environment includes jvm and java class (for example classes.zip in sun jre). Of course jython need jvm,but does it need java class. Thanx
7
by: Jan Gregor | last post by:
Hello I found that jython catches exact java exceptions, not their subclasses. Is there some way to get around this limitation (or error) ? My program has class representing database source...
1
by: scott | last post by:
I installed darwinports and did a "sudo port install jython" ------------------------- scott$ which jython /opt/local/bin/jython ------------------------- Jython works in interactive...
7
by: Jan Gregor | last post by:
Hello folks I want to apply changes in my source code without stopping jython and JVM. Preferable are modifications directly to instances of classes. My application is a desktop app using swing...
2
by: didier.prophete | last post by:
Ok, so I know this is probably a common jython error, but somehow I can't seem to find an answer to this trivial problem. Ok, I have the following (simple) directory structure: $TOP/...
2
by: Brad Pears | last post by:
I am working on a vb.net 2005 project using sql server 2000 as the backend . I am having a bit of problems with date variables... Here is the scenario... I have a table that includes a couple...
20
by: tshad | last post by:
Using VS 2003, I am trying to take a class that I created to create new variable types to handle nulls and track changes to standard variable types. This is for use with database variables. This...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.