Python Gotcha's?

Evan Driscoll driscoll at cs.wisc.edu
Thu Apr 5 14:54:35 EDT 2012


On 4/5/2012 13:24, Chris Angelico wrote:
> I think this example highlights a major point about gotchas: the
> difference between an obvious language feature and a gotcha depends on
> where you come from. To a PHP programmer, 1 and "1" are in many ways
> indistinguishable. To a C programmer, they're utterly incompatible.

I think I agree with this. For instance, I'd consider the fact that this
works in Python to be a gotcha:

  >>> 1 < "abc"
  True

But that's because I like more strongly-typed systems. [I'm most
decidedly not trying to start up that discussion again...]


This is changed in Python 3:

  >>> 1 < "abc"
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
  TypeError: unorderable types: int() < str()

though you can still compare *some* types I consider logically unorderable:

  >>> 0 < True
  True


I think it also has bearing on the ' vs " issue. For instance, I totally
think it's not at all surprising that one can be accepted and the other
not, or that they behave differently. (Though I *do* find it surprising
in the context of JSON given that JS apparently allows either.)

Evan

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 552 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20120405/405c4b15/attachment-0001.sig>


More information about the Python-list mailing list