match or sub problem?

jubafre at brturbo.com jubafre at brturbo.com
Mon Sep 23 00:49:01 EDT 2002


I have this list of strings:
final=['20 0x9', '30 0xa', 'B4 0x8', '30 0xb', 'F0', ' 1', ' 3', ' 5']

and i want to erase the nodes with whitespaces in the begining,
i use  "match" but doesn´t work and "sub", i think the problem is in the "sub", why?

final2=[]
for i in range(len(final)):
    p=re.compile(" ")
    t1=p.match(final[i])
    t=sub(p, "", final[i])
    print t
    final2.append(t)
print final2

None
None
None
None
None
<_sre.SRE_Match object at 0x01420DF0>
<_sre.SRE_Match object at 0x01421B00>
<_sre.SRE_Match object at 0x014211D0>	

p.match find just last 3  nodes with whitespaces in the begining, but the sub replace
al the nodes, like that: ['200x9', '300xa', 'B40x8', '300xb', 'F0', '1', '3', '5']

i want just the last 3 nodes replaced
 ['20 0x9', '30 0xa', 'B4 0x8', '30 0xb', 'F0', '1', '3', '5']

Juliano Freitas
www.gebrasil.hpg.com.br 


More information about the Python-list mailing list