static? + some stuff

Daniel Schüle for_usenet2000 at yahoo.de
Tue Nov 4 13:01:49 EST 2003


[...]

> a, b, c and my_id *are* class attributes. They are actually inherited by

just to adjust myself to the Python's terminology
is the word "member" not widely used in Python?
is it better to say "attributes"?
(for both member functions and member variables)

> instances of foo, but declaring them this way makes them class attributes.
You
> should have done:
>
> class foo:
>    cnt = 0
>    def __init__(self, c=0):
>      foo.cnt += 1
>      self.a = self.b = None
>      self.c = c
>      self.my_id = foo.cnt
> (...)

i think i've got it
the only thing bothering me is that you cant see(less readability) from
..
    cnt = 0
..
is "cnt" considered to be used as "static" or not
what if i would write ...
foo.cnt += 1    #static
and later in one of member functions
self.cnt = 1    #non static

or issues such usage an error ..

and one more question :)
from you code above i dont see the declarations of c, my_id ...
is it sufficient just to write self.c=0 instead of doing it the way i did in
my original
posting (where i put them additional at the top for the readability)?
but do the both ways express logical the same thing?

> Attributes do not need to be *declared* at the top of the class in Python
as in
> C++ or Java: initializing them in the __init__ method is enough, and is
probably
> the safest way to handle them.

as I figured out from tests, one has to initalize every variable with
something
at least with None (and that's fine so)
is there a need to differentiate between assignment and initialization?
(like in C++)
btw in C++ you can also declare member variables at the bottom
indeed that's my favorite style there, but since i am new to Python
i found it more readable (dont ask me why) to place them at the top

i am sure there are must be some "coding styles" in use around ..
pointers in this direction are very approciated


[...]

>      for i in attr:
>          print type(getattr(tmp, i))

exactly this :)

Thank you and all others for the answears

--
Daniel

ps: i hope my english is understandable, if not .. just ask me what i ment
;)






More information about the Python-list mailing list