essentially I need to generate a file with 10 rows. x = 0 fout = open("store.txt", "w") while x <= 10: fout.write(x) x = x + 1 fout.close() This of course doesn't work. I need it to write value of x into file, but whichever way I try doing it ((x),('x'),("x")) the result is not what I need.
what gets written to your file?
just want a file with 1000000 rows, with numbers from 1 - 1000000 in each row. like this: 1 2 3 4 ... 1000000
Do you mean like this mate: http://codepad.org/Tgcju5iA . I will attach my .txt file from running this code.
how about: fout.writelines([str(x) for x in xrange(1, 1000001)])
bmp: What does your if loop do there ? not sure about the os.path.isdir part if os.path.isdir("null.txt"): continue fname.write(str(x)+"\n")
bwCA: cool ! this looks really impressive, just one line with all the stuff. Cheers !
This was the template for a similar program and that if is a leftover. It was just to check whether or not the file is in the correct path, instead of raising an error.
Join our real-time social learning platform and learn together with your friends!