Caveat Emptor: Python rstrip()/lstrip()

0 yorum

Well this one is nasty, lets see:


>>> a="funky_monkey"
>>> a.rstrip("_monkey")
'fu'

A truly WTF? moment. But... string.rstrip() and string.lstrip() works with list of characters not strings. So what python does is treating the {r/l}strip() argument as a list of characters. So it goes over ['_', 'm', 'o', 'n', 'k', 'e', 'y'] list and starts chopping characters from the right as it finds one. If the last character at the right end doesn't match any characters in the list it stops.

Thats it for now folks.

Apple security sucks

0 yorum

Apple's stupid marketing team is getting on my nerves, I already reported them 6 python security vulnerabilities thats already been fixed in upstream & Linux distributions and they didn't give a friggin comment yet.

And now this, this is seriously fucked up, quoting from the article:

Nobody at Apple is ever allowed to speak publicly about anything without marketing approval

A totally good reason to drop MacOSX, damn it.

Python gotcha moment

3 yorum


>>> -1 is True
False
>>> (not -1) is True
False


Something to remember when messing with functions which can return negative numbers.

Update: Solution here is to use not not syntax

>>> (not not -1) is True
True
>>> not (not not -1) is True
False
>>> (not not 1) is True
True
>>> not (not not 1) is True
False