Printing a literal python string in octal

 ̄綄美尐妖づ 提交于 2019-12-11 15:11:16

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/46900475/printing-a-literal-python-string-in-octal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!