Python3 源码中注释的问题

zoe9698 2017-12-02 02:01:29
 def start(self):
'''
Start child process
'''
assert self._popen is None, 'cannot start a process twice'
assert self._parent_pid == os.getpid(), \
'can only start a process object created by current process'
assert not _current_process._config.get('daemon'), \
'daemonic processes are not allowed to have children'
_cleanup()
self._popen = self._Popen(self)
self._sentinel = self._popen.sentinel
_children.add(self)


这是Python3.6 Process模块的源码,想问下大神,为什么“ assert self._popen is None, 'cannot start a process twice' ”出现这种,后面的英文是注释或提示的意思嘛?
...全文
415 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
sanGuo_uu 2017-12-06
  • 打赏
  • 举报
回复
单行注释:在开头加“#” 像这样: #assert self._popen is None, 'cannot start a process twice' #_children.add(self) 多行注释:用3个单引号or3个双引号包起来。 像这样: ''' assert self._popen is None, 'cannot start a process twice' ssert self._parent_pid == os.getpid(), \ '''
zoe9698 2017-12-05
  • 打赏
  • 举报
回复
注释作用的参数???? 另外,大神有空的话帮我看看我提的另一个问题,解决不了了。。。
混沌鳄鱼 2017-12-05
  • 打赏
  • 举报
回复
是我没表达清楚,这里的单引号括起来的字符串是起注释作用的参数。
zoe9698 2017-12-05
  • 打赏
  • 举报
回复
是我没表达清楚,是想问Python中的注释不是只有#或‘’‘这样的方法吗,这里的单引号也是表示注释吗?
混沌鳄鱼 2017-12-02
  • 打赏
  • 举报
回复
你理解的没错 断言语法格式如下: assert expression [, arguments] assert 表达式 [, 参数] assert的异常参数,其实就是在断言表达式后添加字符串信息,用来解释断言并更好的知道是哪里出了问题。 assert len(lists) >=5, '列表元素个数小于5' 当抛出断言异常后,会在提示信息里显示,这个字符串。 >>> assert 2==1, '2不等于1' Traceback (most recent call last): File "<pyshell#6>", line 1, in <module> assert 2==1, '2不等于1' AssertionError: 2不等于1 >>>

37,743

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧