如何在docutils中使用null
发布时间:2021-03-30 12:06:57 所属栏目:Python 来源:互联网
导读:我正在尝试在一个使用null的函数上运行doctest.但是doctest似乎并不喜欢nulls …… def do_something_with_hex(c): do_something_with_hex(x00) x00 return repr(c)import doctestdoctest.testmod() 我看到了
我正在尝试在一个使用null的函数上运行doctest.但是doctest似乎并不喜欢nulls …… def do_something_with_hex(c): """ >>> do_something_with_hex('x00') 'x00' """ return repr(c) import doctest doctest.testmod() 我看到了这些错误 Failed example: do_something_with_hex(' ') Exception raised: Traceback (most recent call last): File "C:Python27libdoctest.py",line 1254,in __run compileflags,1) in test.globs TypeError: compile() expected string without null bytes ********************************************************************** 在这样的测试用例中,我该怎么做才能允许空值? 解决方法您可以转义所有反斜杠,或者将文档字符串更改为 raw string literal:def do_something_with_hex(c): r""" >>> do_something_with_hex('x00') 'x00' """ return repr(c) 使用字符串上的r前缀,字符串中包含反斜杠后面的字符不会发生更改,并且所有反斜杠都保留在字符串中. (编辑:阜阳站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 【Python】Python-numpy逻辑报错:The truth value of an a
- Python Berkeley DB / Sqlite
- 在python中存储100万个键值对的列表
- 在Django模板中使用前导下划线访问dict元素
- python – 递归地按键对嵌套的OrderedDict进行排序
- python – 为什么skimage.transform.rotate比PIL的Image.ro
- 关于python2.7的md5加密遇到的问题(TypeError: Unicode-ob
- 创建一个包含来自另一个字典的特定键值对的Python字典
- Shell脚本定义变量和重新赋值
- python – 将几个正则表达式合并到一个RE中