Friday, 15 February 2013

python - replacing unknown value in string -



python - replacing unknown value in string -

i'm running process dumps bunch of info files in directory. run same process later , diff on directories see has changed. i'm getting bunch of false changes due memory address.

for example:

run 1 gives

0xb7390dd0

run 2 gives

0xb73909c8

i able ignore fact memory addresses different? best way accomplish this?

i can't utilize .replace() don't know address beforehand.

you can create regex match pattern of value , replace matched value

>>> pattern = r'0x\w{8}' >>> matcher = re.compile(pattern) >>> matcher.match('0xb73909c8: has error') <_sre.sre_match object @ 0x01e25288> >>> matcher.match('0xb73909c8: has error').group() '0xb73909c8'

then can

>>> '0xb73909c8: has error'.replace(matcher.match('0xb73909c8: has error').group(), 'address') 'address: has error'

python python-3.x

No comments:

Post a Comment