I have a relatively small python program, which (partly) looks something like the following:
puredata=ClassOne()
stuff=ClassTwo()
for i in range(0,len(chunks)):
print "this is in loop i = %d" % i
temp=chunks[i]
#do some stuff and get variable data.
for k in range(0,len(data)):
print "this is in loop k = %d" % k
if puredata.tb in str(temp[k])!=False:
print "This is valid data..continue calculations"
puredata.pl,puredata.pt,puredata.pi=stuff.extracts(data[k])
print "Length of pl puredata = %d" % len(puredata.pl)
print "Length of pt puredata = %d" % len(puredata.pt)
print "Length of pi puredata = %d" % len(puredata.pi)
else:
pass
The stuff.extracts() spits out 3 lists (something like self.a, self.b, self.c), which I then pass on to puredata.pl,puredata.pt,puredata.pi and ClassOne simply invokes the lists pl,pt,pi. ClassTwo looks something along the lines of:
class ClassTwo():
def __init__(self):
self.a=[]
self.b=[]
self.c=[]
# Start calculations
def extracts(self,soup):
# do stat modelling and calculations
return self.a, self.b,self.c
When I run the loop, I find that data seems to "appended" to puredata.pl,puredata.pt,puredata.pi although I have never used the .append() anywhere in the code. So, in the first loop the length of puredata.pl,puredata.pt,puredata.pi is say 10, and in the next loop it becomes 20, then 30..and so on..
I am finding this very strange - and I am not able to make sense out of it. At some level, this is what I want (I mean the appending of data to a list), but I am baffled why it appends although I have not used .append().
Sorry if this is a kn00b question - python newbie here.
if puredata.tb in str(temp[k])!=False:is parsed as (I think):if (puredata.tb in str(temp[k]))!=False:which makes it more or less equivalent toif puredata.tb in str(temp[k]):