Where do nested functions live?
Frederic Rentsch
anthra.norell at vtxmail.ch
Sun Oct 29 07:58:47 EST 2006
Fredrik Lundh wrote:
> Frederic Rentsch wrote:
>
>
>> At some later point I need to increment my units some more and probably
>> will again a number of times. Clearly this has to go into a function.
>>
>
> since Python is an object-based language, clearly you could make your
> counter into a self-contained object instead of writing endless amounts
> of code and wasting CPU cycles by storing what's really a *single* state
> in a whole bunch of separate variables.
>
This is surely a good point I'll have to think about.
> in your specific example, you can even use an existing object:
>
Of course. But my example wasn't about time. It was about the situation
> t = datetime.datetime.now()
>
> # increment
> t += datetime.timedelta(milliseconds=msec)
>
> print t.timetuple() # get the contents
>
> if you're doing this so much that it's worth streamlining the timedelta
> addition, you can wrap the datetime instance in a trivial class, and do
>
> t += 1500 # milliseconds
>
> when you need to increment the counter.
>
> > This is a little like a shop where the mechanics have to get their
> > tools and work pieces from the manager and hand them back to him when
> > they're done.
>
> that could of course be because when he was free to use whatever tool he
> wanted, he always used a crowbar, because he hadn't really gotten around
> to read that "tool kit for dummies" book.
>
No mechanic always uses a crowbar. He'd use it just once--with the same
employer.
> </F>
>
>
More information about the Python-list
mailing list