Class attributes / methods..... full Python script

Peter Otten __peter__ at web.de
Mon Mar 1 23:12:33 CET 2010


Gabor Urban wrote:

> thanks for the ideas. Here you are the code. Not transcoded from Java
> for I do not know Java enough..
> 
> I am scanning an XML file, and have a large ammount of logging.
> 
> Any ideas are wellcome as before....
> 
> Thnx
> 
> Code:>

>     packages.append(Package)

Replace Package (the class) with package (an instance).

> for i in xrange(oplines.length):
>     data.append(oplines[i])

Python lists don't have a length attribute. You can determine their length 
with len(oplines). To iterate over the items of a list you need not know the 
list's length:

for line in oplines:
    data.append(line)

which can be simplified to

data.extend(oplines)

Peter

PS: Rrread the tutorial



More information about the Python-list mailing list