JonathanB wrote:
> So given that example, is there a clean way to get this output:
>
> Data for Earth:
> Name = Earth
> WTN = 5.0
> Ag = 0
> Na = 0
> ...
> ...
> Notes = None
Sure, save the __init__ parameters explicitly in a dict.
self.data = {"Name": name,
"WTN": WTN,
In article <[EMAIL PROTECTED]>,
JonathanB <[EMAIL PROTECTED]> wrote:
> I can handle the formatting and changing the variable itself, no
> problem, but how do I get a list of all the variables in a class
> instance? I almost put a list in there called vars and appended all
> the variables to it so
Gabriel Genellina <[EMAIL PROTECTED]> wrote:
> The list keeps only the types explicitely enumerated. Other types are
> excluded, as well as names starting with "_". Another criterion would be
> `not attr.startswith('_') and not callable(getattr(obj,attr))`
Why not:
In [1]: class Foo(object):
.
> > class Foo():
> > self.a = "bar"
> > self.z = "test"
> > self.var = 2
>
> That's unlikely to work, though: the code is in the context of the
> class, not one of its methods, so unless you happen to be declaring a
> class inside another class's method it's unlikely that there's going
JonathanB wrote:
> Ok, I know there has to be a way to do this, but my google-fu fails me
> (once more). I have a class with instance variables (or should they be
> called attributes, I'm newish to programming and get really confused
> with OO sometimes), like the one in this example:
>
Instance v
En Mon, 16 Jul 2007 14:25:48 -0300, JonathanB <[EMAIL PROTECTED]>
escribió:
> Ok, I know there has to be a way to do this, but my google-fu fails me
> (once more). I have a class with instance variables (or should they be
> called attributes, I'm newish to programming and get really confused
> w
JonathanB wrote:
> Ok, I know there has to be a way to do this, but my google-fu
> fails me (once more). I have a class with instance variables (or
> should they be called attributes, I'm newish to programming and
> get really confused with OO sometimes),
To complete confusion, those terms vary wi
Ok, I know there has to be a way to do this, but my google-fu fails me
(once more). I have a class with instance variables (or should they be
called attributes, I'm newish to programming and get really confused
with OO sometimes), like the one in this example:
class Foo():
self.a = "bar"
s