Strong/weak typing

Diez B. Roggisch deets at nospam.web.de
Sat Aug 2 15:53:54 CEST 2008


MartinRinehart at gmail.com schrieb:
> I'm writing Python as if it were strongly typed, never recycling a
> name to hold a type other than the original type.
> 
> Is this good software engineering practice, or am I missing something
> Pythonic?

Others pointed out the wrong wording.

As often, this is not a question to be answered with a simple yes or no.

Duck-typing is very ptyhonic, and as such it is very common to write e.g.

if content_as_string:
    inf = StringIO.String(content_as_string)
else:
    inf = open(filename)

inf has two totally different types now, depending on the path taken.

And I personally tend to actually do things like this:

if isinstance(foo, str):
    foo = unicode(str)

Or such.

But that is more a matter of taste - I personally don't like to many 
names lying around, but YMMV.


Diez



More information about the Python-list mailing list