The error message states: NameError: name 'split' is not defined, so the interpreter doesn't recognize split because split is not a built-in function. In order for this to work you have to associate split with the built-in str object.

It isn't to disambiguate, but rather because its a string method - 'blah'.split('a') is equivalent to str.split('blah', 'a'), same as instanceofmyclass.mymethod(arg) is equivalent to MyClass.mymethod(instanceofmyclass, arg) - the string is the self argument to str.split.
–
lvcJun 7 '12 at 5:09

10

This is kind of ugly. I'd rather call the method like a method, e.g. map(lambda x: x.split(), s), or better, just go [x.split() for x in s]
–
Ismail BadawiJun 7 '12 at 5:09

1

@AshwiniChaudhary exactly, that's it. Since we quite frequently attach split to a string it's usually clear which split we mean.
–
LevonJun 7 '12 at 5:09

5

@isbadawi you downvoted because of aesthetics?? I didn't chose this code construct. My posting is in direct response to what the OP posted and answers exactly his concern. If you don't like his code fine, but why downvote my answer for explaining the problem he asked about? He didn't ask for an alternative code construct but an explanation why his code didn't work. I explained this correctly I believe. Your comment to me above really ought to be a comment to the OP at the top of the page.
–
LevonJun 7 '12 at 5:23

3

@isbadawi My answer already clearly states that split is not a built-in. I am not responsible for what you consider "hacky and unpythonic" .. these comments ought to be directed at OP. You also could have posted your own answer (why don't you?). I don't care about the 2 points, more the reasoning which makes no sense to me as I explained above, so there's no point in further discussion.
–
LevonJun 7 '12 at 5:32