Ask your own question, for FREE!
Computer Science 7 Online
OpenStudy (anonymous):

essentially I need to generate a file with n rows. x = 0 y = 0 fout = open("store.txt", "w") while x <= 10: fout.write(x) x = x + 1 fout.close() This of course doesn't work. It tells 'TypeError: expected a character buffer object' and I cant figure out what it means.

OpenStudy (anonymous):

what language is it?

OpenStudy (anonymous):

python

OpenStudy (anonymous):

idk

OpenStudy (anonymous):

I made it work like this: x = 0 y = 0 fout = open("store.txt", "w") while x <= 10: fout.write(str(x)) x = x + 1 fout.close() It casts the integer to a string.

OpenStudy (anonymous):

I'm not sure what you mean by a file with n rows though. Do you mean n lines? In that case, you can use "\n" to make a new line

OpenStudy (anonymous):

Ok thank you. I was missing the little conversion to string with str(x). Cheers for help.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!