Why do I require an "elif" statement here?

John Savage rookswood at suburbian.com.au
Sun Aug 6 23:13:21 EDT 2006


"sp1d3rx at gmail.com" <sp1d3rx at gmail.com> writes:
>-------------------------------
>whitespace = " "
>old_indent = 3
>new_indent = 5
>
>x = "   starts with 3 spaces"
>
>x = x.replace(whitespace*old_indent, whitespace*new_indent)
>-------------------------------
>
>In this example though, it will replace the 3 spaces no matter where
>they are at, not just in the beginning... still, it's probably more
>practical for most use cases.

You'd corner it with:

if x.startswith(' '*3): x=x.replace(' '*3,' '*5,1)
-- 
John Savage                   (my news address is not valid for email)



More information about the Python-list mailing list