为什么`os.CLD_CONTINUED`的Python文档字符串与`int().__doc__`相同?

huangapple go评论73阅读模式
英文:

Why is the python docstring for `os.CLD_CONTINUED` the same as `int().__doc__`?

问题

I am getting familiar with Python and I thought I would do a dir() walk and examine the doc strings.

我正在熟悉Python,我想使用dir()遍历并检查文档字符串。

I started with the "os" module.

我从"os"模块开始。

Why is the python docstring for os.CLD_CONTINUED the same as int().__doc__?

为什么os.CLD_CONTINUED的Python文档字符串与int().__doc__相同?

I first noticed that CLD_CONTINUED had the same doc string as CLD_DUMPED, CLD_KILLED, etc. Then I realized it's the doc string for int().

我首先注意到CLD_CONTINUED的文档字符串与CLD_DUMPEDCLD_KILLED等相同。然后我意识到它是int()的文档字符串。

I imagine this has something to do with object inheritance.

我想象这与对象继承有关。

I checked the Python docs and found https://docs.python.org/3/library/os.html#os.CLD_CONTINUED which says this about CLD__*:

我查看了Python文档并发现https://docs.python.org/3/library/os.html#os.CLD_CONTINUED,其中提到了关于CLD__*的内容:

These are the possible values for si_code in the result returned by waitid().

这些是由waitid()返回的结果中si_code的可能值。

I then went to https://docs.python.org/3/library/os.html#os.waitid which links me to https://docs.python.org/3/library/os.html#os.CLD_EXITED and now I've gone full circle.

然后我转到https://docs.python.org/3/library/os.html#os.waitid,它链接到https://docs.python.org/3/library/os.html#os.CLD_EXITED,现在我已经走了一圈。

Is there someplace else I should look?

还有其他地方我应该查看吗?

I'd like to understand why these si_code docstrings tell me about int().

我想了解为什么这些si_code文档字符串告诉我关于int()的信息。

How can I know when the docstring is not for the thing I'm looking at but for something else? I was really confused at first.

我如何知道文档字符串不是针对我正在查看的内容而是针对其他内容的?起初我感到非常困惑。

英文:

I am getting familiar with Python and I thought I would do a dir() walk and examine the doc strings.

I started with the "os" module.

Why is the python docstring for os.CLD_CONTINUED the same as int().__doc__?

I first noticed that CLD_CONTINUED had the same doc string as CLD_DUMPED, CLD_KILLED, etc. Then I realized it's the doc string for int().

I imagine this has something to do with object inheritance.

I checked the Python docs and found https://docs.python.org/3/library/os.html#os.CLD_CONTINUED which says this about CLD__*:

> These are the possible values for si_code in the result returned by waitid().

I then went to https://docs.python.org/3/library/os.html#os.waitid which links me to https://docs.python.org/3/library/os.html#os.CLD_EXITED and now I've gone full circle.

Is there someplace else I should look?

I'd like to understand why these si_code docstrings tell me about int().

How can I know when the docstring is not for the thing I'm looking at but for something else? I was really confused at first.

答案1

得分: 1

根据[Python文档]: 内置函数 - help() (强调是我的):

> 如果参数是一个字符串,那么该字符串将被查找为模块、函数、类、方法、关键字或文档主题的名称,并在控制台上打印帮助页面。如果参数是任何其他类型的对象,则会生成关于该对象的帮助页面

os.CLD_CONTINUED(以及其他一些)是一个整数值,因此会调用其类的帮助。

> python
> (py_pc064_03.10_test0) [cfati@cfati-5510-0:/mnt/c/Users/cfati]> python
> Python 3.10.11 (main, Apr 5 2023, 14:15:10) [GCC 9.4.0] on linux
> 输入"help"、"copyright"、"credits"或"license"以获取更多信息。
>>>
>>> help(123)
> # 显示“类int(object)的帮助信息”
>>> i = 1
>>> help(i)
> # 与上述相同
>>> import os
>>> os.CLD_CONTINUED, os.CLD_CONTINUED.__class__
> (6, <class 'int'>)
>>> help(os.CLD_CONTINUED)
> # 与上述相同
>>> help(os.CLD_CONTINUED.__class__)
> # 与上述相同
>

英文:

According to [Python.Docs]: Built-in Functions - help() (emphasis is mine):

> If the argument is a string, then the string is looked up as the name of a module, function, class, method, keyword, or documentation topic, and a help page is printed on the console. If the argument is any other kind of object, a help page on the object is generated.

os.CLD_CONTINUED (and others as well) is an int value so the help for its class is invoked.

> python
> (py_pc064_03.10_test0) [cfati@cfati-5510-0:/mnt/c/Users/cfati]> python
> Python 3.10.11 (main, Apr 5 2023, 14:15:10) [GCC 9.4.0] on linux
> Type "help", "copyright", "credits" or "license" for more information.
> >>>
> >>> help(123)
> # Help for 'class int(object)' is displayed
> >>> i = 1
> >>> help(i)
> # Same as above
> >>> import os
> >>> os.CLD_CONTINUED, os.CLD_CONTINUED.__class__
> (6, <class 'int'>)
> >>> help(os.CLD_CONTINUED)
> # Same as above
> >>> help(os.CLD_CONTINUED.__class__)
> # Same as above
>

huangapple
  • 本文由 发表于 2023年5月21日 00:26:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/76296219.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定