【发布时间】:2018-07-29 01:02:50
【问题描述】:
当我运行命令 /usr/bin/pydoc 时,它会打印出来
durd@FelixDu bin$ /usr/bin/pydoc
pydoc - the Python documentation tool
pydoc <name> ...
Show text documentation on something. <name> may be the name of a
Python keyword, topic, function, module, or package, or a dotted
reference to a class or function within a module or module in a
package. If <name> contains a '/', it is used as the path to a
Python source file to document. If name is 'keywords', 'topics',
or 'modules', a listing of these things is displayed.
pydoc -k <keyword>
Search for a keyword in the synopsis lines of all available modules.
pydoc -p <port>
Start an HTTP server on the given port on the local machine. Port
number 0 can be used to get an arbitrary unused port.
pydoc -g
Pop up a graphical interface for finding and serving documentation.
pydoc -w <name> ...
Write out the HTML documentation for a module to a file in the current
directory. If <name> contains a '/', it is treated as a filename; if
it names a directory, documentation is written for all the contents.
但我检查了/usr/bin/pydoc的代码,它显示
durd@FelixDu bin$ cat /usr/bin/pydoc
#!/usr/bin/python
import sys, os
import glob, re
partA = """\
python version %d.%d.%d can't run %s. Try the alternative(s):
"""
partB = """
Run "man python" for more information about multiple version support in
Mac OS X.
"""
sys.stderr.write(partA % (sys.version_info[:3] + (sys.argv[0],)))
dir, base = os.path.split(sys.argv[0])
specialcase = (base == 'python-config')
if specialcase:
pat = "python*-config"
else:
pat = base + '*'
g = glob.glob(os.path.join(dir, pat))
# match a single digit, dot and possibly multiple digits, because we might
# have 2to32.6, where the program is 2to3 and the version is 2.6.
vpat = re.compile("\d\.\d+")
n = 0
for i in g:
vers = vpat.search(i)
if vers is None:
continue
sys.stderr.write("%s (uses python %s)\n" % (i, i[vers.start():vers.end()]))
n = 1
if n == 0:
sys.stderr.write("(Error: no alternatives found)\n")
sys.stderr.write(partB)
sys.exit(1)
如果它运行 /usr/bin/pydoc,它应该打印以下文本,但实际上它不是。
python version 2.7.10 can't run ./pydoc. Try the alternative(s):
(Error: no alternatives found)
Run "man python" for more information about multiple version support in
Mac OS X.
然后我检查了/usr/bin中的文件
durd@FelixDu Documents$ ls -al /usr/bin/pydoc*
-rwxr-xr-x 4 root wheel 925 Jul 16 2017 /usr/bin/pydoc
lrwxr-xr-x 1 root wheel 74 Sep 27 2017 /usr/bin/pydoc2.7 -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/pydoc2.7
似乎当我运行/usr/bin/pydoc 时,它确实运行/usr/bin/pydoc2.7,但我找不到从/usr/bin/pydoc 到/usr/bin/pydoc2.7 的符号链接,所以我很困惑它是如何工作的。谁能帮忙解释一下?
提前致谢。
【问题讨论】:
标签: python python-2.7 command-line pydoc