Windows 7 - 来自 cmd 的 pydoc

发布于 2024-10-02 04:00:02 字数 1700 浏览 1 评论 0原文

好吧,我正经历过这样的时刻,让我怀疑自己使用计算机的能力。这不是我想象中在我的第一篇 SO 帖子中提出的问题,但这里是。

自从我在中断 10 年之后一直想重新开始编程以来,我就开始学习 Zed 的新书《艰难地学习 Python》,而 Python 一直是我想要的。这本书确实对我说话了。话虽这么说,我在命令中遇到了 pydoc 的严重问题。我的系统路径中已包含 c:/python26 中的所有目录,并且无论密码如何,我都可以从命令行执行 pydoc - 但它不接受任何参数。无论我输入什么,我都会得到标准的 pydoc 输出,告诉我可接受的参数。

有什么想法吗?无论如何,我按照 Zed 的建议安装了 ActivePython。

C:\Users\Chevee>pydoc file
pydoc - the Python documentation tool

pydoc.py <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.py -k <keyword>
    Search for a keyword in the synopsis lines of all available modules.

pydoc.py -p <port>
    Start an HTTP server on the given port on the local machine.

pydoc.py -g
    Pop up a graphical interface for finding and serving documentation.

pydoc.py -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.


C:\Users\Chevee>

编辑:新信息,pydoc 在 PowerShell 中工作得很好。作为一名 Linux 用户,我不知道为什么我要尝试使用 cmd ——但我仍然想弄清楚 pydoc 和 cmd 是怎么回事。

编辑2:更多新信息。在cmd...

c:\>python c:/python26/lib/pydoc.py file

...工作得很好。仅使用 PowerShell 中的 pydoc 一切就可以正常工作,无需担心 pwd、扩展名或路径。

Okay, I'm having one of those moments that makes me question my ability to use a computer. This is not the sort of question I imagined asking as my first SO post, but here goes.

Started on Zed's new "Learn Python the Hard Way" since I've been looking to get back into programming after a 10 year hiatus and python was always what I wanted. This book has really spoken to me. That being said, I'm having a serious issue with pydoc from the command. I've got all the directories in c:/python26 in my system path and I can execute pydoc from the command line just fine regardless of pwd - but it accepts no arguments. Doesn't matter what I type, I just get the standard pydoc output telling me the acceptable arguments.

Any ideas? For what it's worth, I installed ActivePython as per Zed's suggestion.

C:\Users\Chevee>pydoc file
pydoc - the Python documentation tool

pydoc.py <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.py -k <keyword>
    Search for a keyword in the synopsis lines of all available modules.

pydoc.py -p <port>
    Start an HTTP server on the given port on the local machine.

pydoc.py -g
    Pop up a graphical interface for finding and serving documentation.

pydoc.py -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.


C:\Users\Chevee>

EDIT: New information, pydoc works just fine in PowerShell. As a linux user, I have no idea why I'm trying to use cmd anyways--but I'd still love to figure out what's up with pydoc and cmd.

EDIT 2: More new information. In cmd...

c:\>python c:/python26/lib/pydoc.py file

...works just fine. Everything works just fine with just pydoc in PowerShell without me worrying about pwd, or extensions or paths.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

假装不在乎 2024-10-09 04:00:02

在 Windows Powershell 中使用: python -m pydoc

示例:

python -m pydoc open

python -m pydoc raw_input

python -m pydoc argv

In Windows Powershell use: python -m pydoc

Examples:

python -m pydoc open

python -m pydoc raw_input

python -m pydoc argv

做个少女永远怀春 2024-10-09 04:00:02

当您在Windows命令提示符下键入文件名时,cmd可以检查Windows注册表中的默认文件关联,并使用该程序打开它。因此,如果 Inkscape 安装程序将 .py 文件与其自己的 python 版本相关联,则 cmd 可能会优先运行该文件并完全忽略 PATH。请参阅此问题

When you type the name of a file at the windows command prompt, cmd can check the windows registry for the default file association, and use that program to open it. So if the Inkscape installer associated .py files with its own version of python, cmd might preferentially run that and ignore the PATH entirely. See this question.

逆夏时光 2024-10-09 04:00:02

根据您的第二次编辑,您的路径中可能有多个 pydoc.py 副本,第一个是“错误”副本,这样当它启动时,它就没有正确的执行环境。

Based on your second edit, you may have more than one copy of pydoc.py in your path, with the 'wrong' one first such that when it starts up it doesn't have the correct environment in which to execute.

坐在坟头思考人生 2024-10-09 04:00:02
python -m pydoc -k/p/g/w <name>
python -m pydoc -k/p/g/w <name>
妥活 2024-10-09 04:00:02

Windows 上 pydoc 的语法:

alt1:

C:\path\PythonXX\python.exe C:\path\PythonXX\Lib\pydoc.py -k/p/g/w X:\path\file_to_doc.py

alt2:

python -m pydoc -k/p/g/w X:\path\file_to_doc.py

其中后者是首选,呵呵。但是,它要求您的 Windows 安装已将 python 注册到环境变量“Path”。

设置 Windows 环境变量:

请访问此站点获取指南关于在哪里可以找到它们。您要寻找的是“Path”。如果选择“路径”并单击“编辑”,您将看到一长排指向不同文件夹的路径。您在此处看到的路径基本上允许您通过输入程序名称而不是其整个路径来在命令行中访问各种程序。所以你要做的就是找到你的Python安装并复制它的完整路径,如下所示:X:\subfolders\PythonXX\ 然后你将它添加到长行路径的最末尾,就像这:

X:\earlier\path\to\something;X:\subfolders\PythonXX\

注意“;”分开不同的路径,请确保不要忘记它。完成后,单击确认/确定,然后您需要重新启动任何已打开的 cmd.exe。

pydoc.py

事实是,pydoc 是标准 python 库的一个模块,并且它也是由 python 提供支持的。据我了解,Windows 环境要求您指定要使用哪个程序来运行某个文件。因此,要运行 pydoc.py 文件,我们将使用:

在 Windows cmd.exe 中打开文件:

X:\subfolders\Python27\python.exe X:\subfolders\Python27\Lib\pydoc.py

pydoc.py 的参数:

pydoc.py 附带了一系列命令基于行的功能允许您输入某些参数:
-k/p/g/w 其中将触发 pydoc.py 程序的不同行为。

通过命令行向程序发送参数:

输入这些参数的语法是我所知道的,总是在x:\pathtofile\filename.suffix之后,用一个简单的分隔符分隔空间。这给了我们最终的:

alt1:

X:\subfolders\Python27\python.exe X:\subfolders\Python27\Lib\pydoc.py -w X:\path\file_to_doc.py

alt2 (将 python 注册到路径):

python -m pydoc -w X:\path\file_to_doc.py

w”选项将为您提供要运行文档的文件的 HTML 文档。请注意, pydoc.py 将(根据我的测试)在当前工作目录中创建文档文件。这意味着在实际运行命令之前,您需要将自己置于所选的文件夹中。

-m 的功能

据我所知,-m 似乎可以处理注册表项,至少在 msiexec.exe 中是这样。我想它可能会以这种方式用于一般程序。所以我的推测是,如果应用“-m”,后面的参数路径将被重写,以便 .exe 文件将用作路径引用。但正如所说,相当投机。

-m 重写所有必需的计算机特定注册表项。 (在 msiexec.exe 中)根据 Microsoft

Syntax for pydoc on windows:

alt1:

C:\path\PythonXX\python.exe C:\path\PythonXX\Lib\pydoc.py -k/p/g/w X:\path\file_to_doc.py

alt2:

python -m pydoc -k/p/g/w X:\path\file_to_doc.py

Of which the latter is the one to prefer, duh. However it requires your windows installation to have registered python to the environment variable "Path".

Setup windows environment variables:

Look at this site for a guide on where to find them. The one you'll be looking for is "Path". If you select Path and click Edit you will see a long row of paths pointing to different folders. The Path's you see here is what allows you to basically reach a veriety of programs in the command line by just entering the name of the program, instead of the whole path to it. So what you want to do here is to locate your Python installation and copy its full path like this: X:\subfolders\PythonXX\ Then you add it to the very end of the long row of Path's like this:

X:\earlier\path\to\something;X:\subfolders\PythonXX\

Notice the ";" that seperates the different paths, make sure not to forget it. When done, click to confirm/Ok, then you would need to restart any cmd.exe that's already open.

The pydoc.py

The thing is that pydoc is a module of the standard python lib, and it's also powered by python. The windows environment, of what I understand, requires you to specify with which program you want to run a certain file with. So to run the pydoc.py-file we would use:

Open file in windows cmd.exe:

X:\subfolders\Python27\python.exe X:\subfolders\Python27\Lib\pydoc.py

pydoc.py's arguments:

pydoc.py comes with a veriety of command line-based features that allows you to enter certain arguments:
-k/p/g/w of which will trigger different behaviours of the pydoc.py-program.

Send arguments to a program through command line:

The syntax to enter these arguments is of what I know always after the x:\pathtofile\filename.suffix, seperated by a simple space. Which gives us the final:

alt1:

X:\subfolders\Python27\python.exe X:\subfolders\Python27\Lib\pydoc.py -w X:\path\file_to_doc.py

alt2 (with python registered to path):

python -m pydoc -w X:\path\file_to_doc.py

The "w"-option will give you a HTML-documentation for the file you want to run documentation on. Notice that pydoc.py will (according to my tests) create the documentation-file in the current working directory. Meaning that you will need to place yourself in a folder of choice before you actually run the command.

The function of -m

Of what I can find, the -m seem to handle registry entries, atleast in the msiexec.exe. I guess it might be used for programs in general this way. So my speculative idea of it is that if "-m" is applied, the pursuing arguments paths will be rewritten so that the .exe-file will be used as a path-reference. But as said, rather speculative.

-m Rewrites all required computer-specific registry entries. (in msiexec.exe) According to Microsoft

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文