String search
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Fri Feb 27 05:17:18 EST 2009
En Fri, 27 Feb 2009 07:33:44 -0200, pranav <pranny at gmail.com> escribió:
> Greeting fellow pycoders,
>
> I have a script that browses large codes and replaces certain text
> with some other text. Of lately i observed an issue.Some of the
> original text were like
>
> <cfif IsDefined("attributes.SOFTPREREQ")>
> ,N'#attributes.SOFTPREREQ#'
> </cfif>
>
> My module does scan this code and suggests replacement to this code.
> But when i use the string.replace() method, it just fails. A
> string.find() for above code in the whole file returns code -1.
> Where am i going wrong? I figure it could be something to do with
> character encoding or else.
Do you mean, you look for those three complete lines with a single
xxxx.find(...)?
Hard to guess... maybe there is some withespace at the end of a line, some
additional leading whitespace in the second line, a tab character instead
of spaces, maybe those ' are instead ´ or `, maybe the file does not use
\n as a line termination, maybe the file encoding doesn't match what you
expect...
If string.find() does return -1, it is because the text you're looking for
is NOT inside the string. No use in questioning that. If you think the
text IS there, get a decent hex editor and examine the file near the
supposed match, character by character, and see WHERE is the difference
(there MUST be a difference).
--
Gabriel Genellina
More information about the Python-list
mailing list