[英]How do i insert a new line after every dictionary key pair print using dictionary comprehension as done by the pprint function in Python?
[英]How to print without new line using pprint
如何像打印一样pprint.pformat字符串。 我正在使用pprint,因为我需要使用缩进
test = 'google\\nfirefox'
import pprint
pprint.pformat(test)
output is "'enable\\\\nshow'"
预期的结果就像
print (test)
google\nfirefox
尝试:
test = 'google\\nfirefox'
import pprint
string = pprint.pformat(test) # google\\nfirefox
print (eval(string)) # google\nfirefox
输出:
google\nfirefox
eval()
方法解析传递给此方法的表达式,并在程序中运行python表达式(代码)。
这是一件很奇怪的事情,但我希望这对您有用
test = 'google\\nfirefox'
pprint.pformat(test).split("\\")[0] + "\\" + pprint.pformat(test).split("\\")[2]
只是一些非常奇怪的字符串操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.