Why do I require an "elif" statement here?

sp1d3rx at gmail.com sp1d3rx at gmail.com
Tue Aug 15 19:29:18 EDT 2006


John Savage wrote:
> "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)

As others have stated, this will only get lines that start with only 1
set of "old_indent" and not multiples of "old_indent".
> --
> John Savage                   (my news address is not valid for email)




More information about the Python-list mailing list