|
Hi,
I am trying to make an assembler for symbol free programs by Python. I used the strip function to remove blanks before the initial letter of each line in the Assemble file. However the error 'string index out of range' occurred and I could not figure out why.
I wrote a code as shown below just to figure out the error reason. You can see a sample file 'ex0.txt' below as well.
--------------------------------------------
f1=open('ex0.txt','r')
f2=open('ex1.txt','w')
for i in f1:
f2.write(i.strip()[0]+'\n')
f1.close()
f2.close()
--------------------------------------------
(ex0.txt)
//long time no see
//Hi
Name
Ichiro
--------------------------------------------
I really appreciate it if you could help me figure out.
|