Newbie seeks help on case preserving substitutions

Nicola Musatti objectway at divalsim.it
Wed Jun 27 04:10:27 EDT 2001


Marcin 'Qrczak' Kowalczyk wrote:
[...]
> So there are only three case forms. You can perform three passes over
> each line, each pass being a case-sensitive replacement of constant
> strings prepared before the loop.
> 
> This can be done without regexps, using .replace(old,new) method of
> strings (or string.replace(s,old,new) in Python < 2.0).

Dang! I underspecified my problem. I do need regexps because my files
may contain different strings, all to be substituted by the same string.
It all comes from the reorganization of a large application which is
split in different projects, where I used the same naming convention
across all projects, based on the project names.

So I may have files named "PRojName.cpp", containaining macros named
PROG_SOMETHING, which are built into projname.dll; now I'm combining
some projects together and I'm using my script to substitute old names
with the new one. The snippet I presented in my original post is
surrounded by a loop on all the files in the new project. What I've done
is modify the inner loop to take into account the new string's length
and to check the first, third and fourth letter in the original string
to decide which variation to write in.

For a first "useful" Python program I'm reasonably satisfied, even if it
is a bit too C-ish (or shellish, if you like). Thank you to everybody
for your suggestions!

Cheers,
Nicola



More information about the Python-list mailing list