[英]Python file.write() to write backspace to a file
How can i write \\b to a file using the function file.write() in python 如何使用python中的函数file.write()将\\ b写入文件
Tried file.write('\\b\\b\\b') but it only adds junk characters to my file 尝试过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')
Expect to clear the last instance of ** written from the line file.write('\\n'+'**')
期望清除从行file.write('\\n'+'**')
写入的**的最后一个实例
Don't write the \\n**
in the first place if you might want to delete them later. 如果您以后想删除它们,请不要首先写\\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)
Starting with PYthon 3.8, you'll be able to combine the assignment and the if
statement: 从PYthon 3.8开始,您将能够将赋值和if
语句结合在一起:
if resources := '\n**'.join(...):
file.write(resources)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.