How to create a new text file using Python

后端 未结 4 1057
抹茶落季
抹茶落季 2020-12-09 01:00

I\'m practicing the management of .txt files in python. I\'ve been reading about it and found that if I try to open a file that doesn\'t exists yet it will create it on the

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-09 01:35

        file = open("path/of/file/(optional)/filename.txt", "w") #a=append,w=write,r=read
        any_string = "Hello\nWorld"
        file.write(any_string)
        file.close()
    

提交回复
热议问题