Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Python 2.7字典中显示未转换的字符串_Python_Python 2.7_Dictionary_Escaping - Fatal编程技术网

在Python 2.7字典中显示未转换的字符串

在Python 2.7字典中显示未转换的字符串,python,python-2.7,dictionary,escaping,Python,Python 2.7,Dictionary,Escaping,在Python中打印字符串将打印字符串的未缩放版本。但是,如果字符串是字典中的键或值,则打印字典将打印字符串的转义版本。有没有一种简单的方法来显示字典中的字符串?下面是我所说的行为的一个例子: >>> thing = {'a' : '\d'} >>> thing {'a': '\\d'} >>> print thing {'a': '\\d'} >>> print thing['a'] \d 容器使用其表示法显示包含的字符

在Python中打印字符串将打印字符串的未缩放版本。但是,如果字符串是字典中的键或值,则打印字典将打印字符串的转义版本。有没有一种简单的方法来显示字典中的字符串?下面是我所说的行为的一个例子:

>>> thing = {'a' : '\d'}
>>> thing
{'a': '\\d'}
>>> print thing
{'a': '\\d'}
>>> print thing['a']
\d

容器使用其表示法显示包含的字符串(以及包含的任何其他内容);可以安全地粘贴回Python的值。这种表示法包括对所有非ASCII和不可打印的内容使用转义码,并将反斜杠加倍,以防止将其解释为转义序列开始。是否有其他方法显示容器,或者这是我必须自己实现的吗?恐怕您必须自己实现。