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

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

本文介绍了以八进制打印文字python字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于未知原因,我是元数据的使用者,需要使用八进制格式来显示该元数据.我试图弄清楚如何将其表示为八进制.示例:

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'

我如何获取x以八进制编码打印分配的方式?

how do i get x to print the way it was assigned, which is in octal encoding?

推荐答案

您不能;那个表示丢失了.如果要输出"\ 022",则需要自己处理或存储"\\022".

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.

这篇关于以八进制打印文字python字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 20:11