Continue writing in same line of file

后端 未结 3 1551
难免孤独
难免孤独 2020-12-17 01:57

I have opened the file I want to write to using:

data = open(\'input\',\'a\')

using a loop, I want to write some words to the file in the s

相关标签:
3条回答
  • 2020-12-17 02:14

    Try removing data.write("\n") .

    0 讨论(0)
  • 2020-12-17 02:21
    while loop:
    for loop:
        /*do something
        */
        if some_condition:
            data.write(str(tag)+"")
    data.write(" ")
    

    In other words, remove the data.write("\n");

    0 讨论(0)
  • 2020-12-17 02:33

    Remove the newline at the end of tag before writing it.

    data.write(str(tag).rstrip('\n'))
    
    0 讨论(0)
提交回复
热议问题