[英]print specific string result execution on python
ii only want to save specific print result of every execution of code on text file ii 只想在文本文件中保存每次代码执行的特定打印结果
i try with我试试
if to,from_addr != '0x':
print(To:,From:)
os.system(f'echo {To:} {From:} >> output.txt')
but everytime fail, also I also want that every time a new result appears, a new line is added and not replace the later output但每次都失败,我也希望每次出现新结果时,添加一个新行而不是替换后面的 output
enter image description here在此处输入图像描述
i try with我试试
with open("Output.txt", "w") as text_file:
print(f"To:" "From:" {to} {from_addr}", file=text_file)
Use append
mode and fix f-strings:使用
append
模式并修复 f 弦:
to = 'destination'
from_addr = 'source'
# Use append mode
with open("Output.txt", "a") as text_file:
if not (to.startswith('0x') or from_addr.startswith('0x')):
print(f"To: {to}\nFrom: {from_addr}", file=text_file)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.