read() file??
Skip Montanaro
skip at pobox.com
Tue Sep 10 15:14:32 EDT 2002
Juliano> I have a file with assembler instruction and i want read the
Juliano> lines of the file and put in a list of string, this is easy to
Juliano> do, but i don´t want to consider the caracteres "/" and the
Juliano> othes after him.
Juliano> file.asm:
Juliano> ADD D1 /coment1
Juliano> LDA D2 /coment2
Juliano> list of strings:
Juliano> X=[ 'ADD D1' , 'LDA D2' ]
How about:
import re
x = []
for line in file("file.asm"):
line = re.sub(r"\s*/.*", "", line.strip())
x.append(line)
?
--
Skip Montanaro
skip at pobox.com
consulting: http://manatee.mojam.com/~skip/resume.html
More information about the Python-list
mailing list