[Python-Dev] Proof of the pudding: str.partition()
Ron Adam
rrr at ronadam.com
Wed Aug 31 06:27:23 CEST 2005
Fredrik Lundh wrote:
> Ron Adam wrote:
>
>
>>For cases where single values are desired, attribues could work.
>>
>>Slicing:
>> line = line.partition(';').head
>> line = line.partition('#').head
>>
>>But it gets awkward as soon as you want more than one.
>>
>> sep, port = host.partition(':').head, host.partition(':').sep
>
>
> unless you go for the piece approach
>
> host, port = host.piece(":", 1, 2)
>
> (which, of course, is short for
>
> host, port = host.piece(":").group(1, 2)
>
> )
I'm not familiar with piece, but it occurred to me it might be useful to
get attributes groups in some way. My first (passing) thought was to do...
host, port = host.partition(':').(head, sep)
Where that would be short calling a method to return them:
host, port = host.partition(':').getattribs('head','sep')
But with only three items, the '_' is in the category of "Looks kind of
strange, but I can get used to it because it works well.".
Cheers,
Ron
More information about the Python-Dev
mailing list