Many newbie questions regarding python
Grant Edwards
invalid at invalid.invalid
Fri Oct 8 13:04:51 EDT 2010
On 2010-10-07, Rog??rio Brito <rbrito at ime.usp.br> wrote:
> If possible, I would like to simply declare the list and fill it
> latter in my program, as lazily as possible (this happens notoriously
> when one is using a technique of programming called dynamic
> programming where initializing all positions of a table may take too
> much time in comparison to the filling of the array).
At first you say you want a list, later you say you want an array.
They're two different things. Arrays are variable-length and can be
heterogeneous. If what you really want is a fixed-length, homogeneous
array, then use an array instead of a list:
http://docs.python.org/library/array.html
> If I declare a class with some member variables, is is strictly
> necessary for me to qualify those members in a method in that class?
Yes.
> I get an annoying message when I try to call the g method in an
> object of type C, telling me that there's no global symbol called f.
> If I make g return self.f instead, things work as expected, but the
> code loses some readability.
That's a matter of opinion. Some of us _like_ self.f since it
explicitly shows the reader that f isn't a global or local but a class
or instance variable. Any time you make the reader/maintainer guess
what something is, that's a bug waiting to happen.
> Is there any way around this or is that simply "a matter of life"?
Well, that's how Python works. I won't comment on "life".
--
Grant Edwards grant.b.edwards Yow! I feel like a wet
at parking meter on Darvon!
gmail.com
More information about the Python-list
mailing list