我已经在Python中应用了一个main函数,说:
> [1] 2
然后我得到这样的结果:
def main():
"some code here"
if __name__ == '__main__':
main()
我想将结果保存在txt和csv文件中以便稍后操作它保留相同的结构:括号,单词,逗号等等。我该怎么做?提前谢谢。
答案 0 :(得分:0)
希望这是你想要的:
def main():
return [['This is my car not yours'], ['He answered me sorry'], ['no problem'], ['\nYou are crazy'], ['All cars are the same']]
if __name__ == '__main__':
with open('output.txt', 'w') as f:
a = ('').join(str(main()))
f.write(a)