I have a text file which has three lines. I want to read those three lines as L1, L2 and L3 and count the character of L1, L2 and L3 as n1, n2 and n3. I tried as follows:
f=open(sys.argv[1],'r')
L1=f.readline()
L2=f.readline()
L3=f.readline()
if L1[-1]=='\n': L1=L1[:len(L1)-1]
if L2[-1]=='\n': L2=L2[:len(L2)-1]
if L3[-1]=='\n': L3=L3[:len(L3)-1]
n1=len(L1); n2=len(L2); n3=len(L3)
print L1, n1, L2, n2, L3, n3
The above script is working fine. But I wanted to know if there is a better/easier way to get L1, L2 and L3. Thanks in advance!