I want to write the output result of a Python program to a file ...
example.py
file_path = "./test.txt"
food = "orange"
text="My favorite food is "+ food
with open(file_path, mode='w') as f:
f.write(text)
$ cat ./text.txt
My favorite food is orange
Allows code to start and end
open() The function used to open the file 【argument】 The path of the file you want to open
write() A method that has the role of writing a string to a file
Recommended Posts