I have some code that simplified looks like this:
class cKBO(object):
def __init__(cls):
cls.a = 0.
cls.e = 0.
lines = open("test.file","r").readlines()
nlist = []
for line in lines:
obj = cKBO()
(a,e) = line.split
obj.a = float(a)
obj.e = float(e)
nlist.append(obj)
I would now like to plot a vs e for all the obj objects in nlist.
how do I do that? I tried
plot(nlist[:].a,nlist[:].e,'ko')
show()
but that resulted in
raceback (most recent call last):
File "/Users/tgrav/Work/MyCode/Python/MOPS/ckbos.py", line 108, in ?
plot(nlist[:].a,nlist[:].e,'ko')
AttributeError: 'list' object has no attribute 'a'
Which is understandable. But how do I most easily convert a list of class
objects into two lists of object variables?
Cheers
Tommy
Hello Tommy,
I would like to do such convertings, too, but I think there is no such fast
way in python. I'm using the 'for statement' to iterate over a list of
objects and save their properties into a new list.
best regards,
Matthias
···
On Friday 04 May 2007 17:54, Tommy Grav wrote:
I have some code that simplified looks like this:
class cKBO(object):
def __init__(cls):
cls.a = 0.
cls.e = 0.
lines = open("test.file","r").readlines()
nlist =
for line in lines:
obj = cKBO()
(a,e) = line.split
obj.a = float(a)
obj.e = float(e)
nlist.append(obj)
I would now like to plot a vs e for all the obj objects in nlist.
how do I do that? I tried
plot(nlist[:].a,nlist[:].e,'ko')
show()
but that resulted in
raceback (most recent call last):
File "/Users/tgrav/Work/MyCode/Python/MOPS/ckbos.py", line 108, in ?
plot(nlist[:].a,nlist[:].e,'ko')
AttributeError: 'list' object has no attribute 'a'
Which is understandable. But how do I most easily convert a list of
class
objects into two lists of object variables?
Cheers
Tommy
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options