regex - Best way to replace \x00 in python lists? -


i have list of values parsed pe file include /x00 null bytes @ end of each section. want able remove /x00 bytes string without removing "x"s file. have tried doing .replace , re.sub, not success.

using python 2.6.6

example.

import re  list = [['.text\x00\x00\x00'], ['.data\x00\x00\x00'], ['.rsrc\x00\x00\x00']]  while count < len(list):     test = re.sub('\\\\x00', '', str(list[count])     print test     count += 1  >>>tet  (removes x, want keep it) >>>data >>>rsrc 

i want following output

text data rsrc

any ideas on best way of going this?

>>> l = [['.text\x00\x00\x00'], ['.data\x00\x00\x00'], ['.rsrc\x00\x00\x00']] >>> [[x[0]] x in l] [['.text\x00\x00\x00'], ['.data\x00\x00\x00'], ['.rsrc\x00\x00\x00']] >>> [[x[0].replace('\x00', '')] x in l] [['.text'], ['.data'], ['.rsrc']] 

or modify list in place instead of creating new one:

for x in l:     x[0] = x[0].replace('\x00', '') 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -