python类CLI变量转储

nie*_*aki 1 python command-line-interface

当我在交互式shell中使用python时,我可以通过调用它们的名称轻松转储变量.

>>> x = b'\xA5'
>>> x
'\xa5'
>>> print x
?
Run Code Online (Sandbox Code Playgroud)

如您所见,行为与行为不同print.如何在普通脚本中模拟这个类似CLI的变量转储?

sam*_*ias 5

使用repr()内置函数:

>>> x = '\xa5'
>>> print repr(x)
'\xa5'
Run Code Online (Sandbox Code Playgroud)