[英]Python file.write() to write backspace to a file
如何使用python中的函数file.write()将\\ b写入文件
尝试过file.write('\\ b \\ b \\ b')但它只会向我的文件中添加垃圾字符
for path in data['paths']:
file.write(path['method'] + '*')
file.write(path['url'] + '*')
for resources in path['resources']:
file.write(resources['key'])
file.write('\n'+'**')
file.write('\b\b\b')
期望清除从行file.write('\\n'+'**')
写入的**的最后一个实例
如果您以后想删除它们,请不要首先写\\n**
。
for path in data['paths']:
file.write(path['method'] + '*')
file.write(path['url'] + '*')
resources = '\n**'.join(x['key'] for x in path['resources'])
if resources:
file.write(resources)
从PYthon 3.8开始,您将能够将赋值和if
语句结合在一起:
if resources := '\n**'.join(...):
file.write(resources)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.