io - Python writing to file multiple lines at once -


i have file following content.

1 2 3 

now want write 4,5 , 6 file content below

1 2 3 4 5 6 

instead of writing 4,5 , 6 doing file.write("4" + '\n'), file.write("5" + '\n'), file.write("6" + '\n'), how can write last 3 number calling file.write command once?

update: not know in advance how many number adding file. numbers added stored in giant list.

you can this:

file.write("%s \n %s \n %s \n" % (string1, string2, string3)) 

i'm assuming strings want write more complicated single number.

update:

since don't know content you're writing ahead of time, can this:

stringtowrite = "" x in listofnumbers:     stringtowrite += x + "/n"  file.write(stringtowrite) 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -