擅长:python、mysql、java
<blockquote>
<p>If you are using Python3.</p>
</blockquote>
<p>然后您可以使用<a href="https://docs.python.org/3/library/functions.html#print" rel="noreferrer">Print Function</a>:</p>
<pre><code>your_data = {"Purchase Amount": 'TotalAmount'}
print(your_data, file=open('D:\log.txt', 'w'))
</code></pre>
<blockquote>
<p>For python2</p>
</blockquote>
<p>这是Python将字符串打印到文本文件的示例</p>
<pre><code>def my_func():
"""
this function return some value
:return:
"""
return 25.256
def write_file(data):
"""
this function write data to file
:param data:
:return:
"""
file_name = r'D:\log.txt'
with open(file_name, 'w') as x_file:
x_file.write('{} TotalAmount'.format(data))
def run():
data = my_func()
write_file(data)
run()
</code></pre>