Andrew Mobbs (mobbsy) wrote,
Andrew Mobbs

Ah, Python's syntax just got a little bit nicer.

I used to dislike having to write things like:
if line.find("<!-- NAME:") >= 0:

Because it looked ugly, and looking ugly isn't what Python code is meant to be. <troll>If I wanted my code to look ugly, I'd use Perl</troll>.

Now in Python 2.3:
>>> foo='bc'
>>> bar='abcd'
>>> foo in bar

Actually, the jibe at Perl is a little unfair in this case. The reason the old find method seemed so ugly to me was mostly in comparison to if(/foo/) in Perl. In retrospect missing the if substr in string: was a something of a wart given the other uses of the "in" infix operator.

  • (no subject)

    Last week I poured the cremated remains of my father into a river. From there, that material will flow through the town he lived in, into the sea,…

  • Moving house!

    We're moving house soon… details to follow in a less public post, or email me. However, we're getting rid of some bits and pieces of…

  • (no subject)

    Yesterday, I made sausages. This was sufficiently exciting to cause me to actually write something on LJ for once. One of our wedding gifts was a…

  • Post a new comment


    default userpic

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.