简体   繁体   English

以八进制打印文字python字符串

[英]Printing a literal python string in octal

For reasons unknown I am the consumer of metadata that needs to be displayed in octal format to be used. 由于未知的原因,我是元数据的使用者,该元数据需要以八进制格式显示才能使用。 I am trying to figure out how to represent it as an octal. 我试图弄清楚如何将其表示为八进制。 Example: 例:

x = "\n)\n\022foobar"
print x 

)
foobar

print repr(x)
'\n)\n\x12foobar'

how do i get x to print the way it was assigned, which is in octal encoding? 如何获取x以八进制编码打印分配的方式?

You can't; 你不能 that representation is lost. 那个表示丢失了。 If you want to output "\\022" then you need to either process it yourself or you need to store "\\\\022" instead. 如果要输出“ \\ 022”,则需要自己处理或存储"\\\\022"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM