如何在python 3.1中的txtfile中编写输出?

时间:2014-06-02 21:39:26

标签: python

我有一些结果我可以像这样打印出来:

print ("BugID : ", bugID, '\n' , "Bug Description : ", desc, '\n' , "Classification : ", classification, '\n', "Component : ", component, '\n', "Version : ", version, '\n',  "Operating System : ", opsystem, '\n',  "Status : ", status )

如何在文本文件中编写它们?

2 个答案:

答案 0 :(得分:0)

with open("log.txt","w") as my_log_file:
    print("a","bunch","of","stuff",file=my_log_file)
                                   # ^ this is the part thats important

我认为你需要的只是

这里解释https://docs.python.org/3/library/functions.html?highlight=print#print

答案 1 :(得分:0)

来自http://www.tutorialspoint.com/python/python_files_io.htm

# Open a file
fo = open("foo.txt", "wb")
fo.write( "Python is a great language.\nYeah its great!!\n");

# Close opened file
fo.close()