I am using a while loop like
while a>0:
a=a+1
a1=open("/python25/file1.txt","r+")
a2=str(a)
a3=a1.write(a2)
It is storing only the last value of a, but how can I store any row or all the rows in file?

Try this ...

# open a file for appending
fap = open("file1.txt", "a")

n = 0
# append numbers 1 to 9 to the file
while n < 9:
       n = n + 1  # or n += 1
       fap.write(str(n))

fap.close()

Thank you Sir. I was thinking and tried it. Problem looks resolved.
Thank you for giving me your valuable time.
Regards,
Subhabrata Banerjee.
IISC,
Bangalore.
INDIA.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.