Getting rid of \x## in strings (Python) -


i need extract description file, looks this: "tes4!\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0f\x00\x00\x00hedr\x0c\x00\xd7\xa3p?h\x03\x00\x00\x00\x08\x00\xffcnam\t\x00martigen\x00snam\xaf\x00mart's mutant mod - rc4\n\ndiverse creatures & npcs, new creatures & npcs, dynamic size , stat scaling, increased spawns, improved ai, improved factions, , more.\n\n\x00mast\r\x00fallout3.esm\x00data\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00mast\x16\x00mart's mutant mod.esm\x00data\x08"

i've laready figured out how part need, there's still unwanted data in there don't know how rid of: \xaf\x00mart's mutant mod - rc4\n\ndiverse creatures & npcs, new creatures & npcs, dynamic size , stat scaling, increased spawns, improved ai, improved factions, , more.\n\n\x00

should become: mart's mutant mod - rc4\n\ndiverse creatures & npcs, new creatures & npcs, dynamic size , stat scaling, increased spawns, improved ai, improved factions, , more.\n\n\

basically, need way rid of \x## stuff (which if left in there end weird characters when displayed in gui), haven't managed remove them.

[in case wondering, it's .esp files fo3 i'm messing around with.]

you try:

import string  cleaneddata = ''.join(c c in data if c in string.printable) 

this assumes have data in string.

here's how works me:

>>> s = """tes4!\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0f\x00\x00\x00hedr\x0c\x00\xd7\xa3p?h\x03\x00\x00\x00\x08\x00\xffcnam\t\x00martigen\x00snam\xaf\x00mart's mutant mod - rc4\n\ndiverse creatures & npcs, new creatures & npcs, dynamic size , stat scaling, increased spawns, improved ai, improved factions, , more.\n\n\x00mast\r\x00fallout3.esm\x00data\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00mast\x16\x00mart's mutant mod.esm\x00data\x08""" >>> print ''.join(c c in s if c in string.printable)tes4!hedr          p?hcnam    martigensnammart's mutant mod - rc4  diverse creatures & npcs, new creatures & npcs, dynamic size , stat scaling, increased spawns, improved ai, improved factions, , more.  fallout3.esmdatamastmart's mutant mod.esmdata >>>  

not ideal can see might @ least first step.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -