string character count
Emile van Sebille
emile at fenx.com
Tue Jun 30 18:58:17 EDT 2009
On 6/30/2009 1:43 PM nn said...
> On Jun 30, 1:56 pm, MRAB <pyt... at mrabarnett.plus.com> wrote:
<snip>
>> >>> len("text12345.txt".split(".", 1)[0])
>> 9
>> >>> len("textstringwithoutdot".split(".", 1)[0])
>> 20
>
> Also:
>
>
>>> len("text.12345.txt".partition('.')[0])
4
>>> len("text.12345.txt".rpartition('.')[0])
10
>>>
unless you've got file names like text.12345.txt, where you might prefer
rpartition.
>>> len("text.12345.txt".partition('.')[0])
4
>>> len("text.12345.txt".rpartition('.')[0])
10
>>>
Emile
More information about the Python-list
mailing list