Seeking assistance - string processing.
Peter Otten
__peter__ at web.de
Tue Nov 14 06:07:51 EST 2006
billpaterson2006 at googlemail.com wrote:
> Thanks so much, a really elegant solution indeed.
>
> I have another question actually which I'm praying you can help me
> with:
>
> with regards to the .jpg conversion to .jpg]] and .gif -> .gif]]
>
> this works, but only when .jpg/.gif is on it's own line.
>
> i.e:
>
> .jpg
>
> will get converted to:
>
> .jpg]]
>
> but
>
> Image:test.jpg
>
> gets converted to:
>
> [[Image:test.jpg
>
> rather than
>
> [[Image:test.jpg]]
>
> ------------------
>
> Hope you can help again! Cheers
It does not do the right thing in all cases, but maybe you can get away with
for line in lines:
if line.startswith("==="):
line = line.rstrip() + "===\n"
line = line.replace("--------------------","----")
line = line.replace("img:","[[Image:")
line = line.replace(".jpg",".jpg]]")
line = line.replace(".gif",".gif]]")
output_lines.append(line)
Peter
More information about the Python-list
mailing list