Strong/weak typing
Mel
mwilson at the-wire.com
Mon Aug 4 10:02:30 EDT 2008
Jorgen Grahn wrote:
> I reuse names though, mostly because I don't want to invent additional
> names which would feel "overburdened". I like this example better:
>
> months = range(1, 13)
> # do something with the months-as-numbers list,
> # and then:
> months = [ monthname(x) for x in months ]
> # do something where we only need the names
>
> Your comment "something that follows the evolution of the data"
> applies here. It's the same data, but refined to a more usable form.
[ ... ]
> I only do this very locally, like in a simple function.
Yes. That example looks particularly good.
Somebody emailed me privately with a poster-child for this technique, which,
now that I've been reminded, I *do* use ("locally" applies strongly here):
def f(a):
a = int (a)
# ...
or, in a slightly different context:
class ThisClass (object):
# ...
def __add__ (self, other):
if not isinstance (other, ThisClass):
other = ThisClass (other)
Mel.
More information about the Python-list
mailing list