Hi,
I have a .txt file containing data like this:
0,Rent1,Expense,16/02/2010,1,4000,4000
0,Car Loan1,Expense,16/02/2010,2,4500,9000
0,Flat Loan1,Expense,16/02/2010,2,4000,8000
0,Rent2,Expense,16/02/2010,1,4000,4000
0,Car Loan2,Expense,16/02/2010,2,4500,9000
0,Flat Loan2,Expense,16/02/2010,2,4000,8000
Now i want to replace the line 4 with the new items like:
0,Loan,Expense,19/02/2010,2,5000,10000
I use the following code:
newline='0,Loan,Expense,19/02/2010,2,5000,10000'
lnum=1
for line in fileinput.FileInput("sample.txt",inplace=1):
if lnum=='4':
result = newline
lnum=lnum+1
else:
result=line
lnum=lnum+1
sys.stdout.write(result)
But it shows the in file like:
0,Rent1,Expense,16/02/2010,1,4000,4000
0,Car Loan1,Expense,16/02/2010,2,4500,9000
0,Flat Loan1,Expense,16/02/2010,2,4000,8000
0,Loan,Expense,19/02/2010,2,5000,100000,Car Loan2,Expense,16/02/2010,2,4500,9000
0,Flat Loan2,Expense,16/02/2010,2,4000,8000
How can i solve this? Any one can help me? Plz..........
Thanks in advance, Nimmy