开发者

Windows 7 - pydoc from cmd

开发者 https://www.devze.com 2023-01-24 05:28 出处:网络
Okay, I\'m having one of those moments that makes me question my abi开发者_如何转开发lity to use a computer.This is not the sort of question I imagined asking as my first SO post, but here goes.

Okay, I'm having one of those moments that makes me question my abi开发者_如何转开发lity 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.


In Windows Powershell use: python -m pydoc

Examples:

python -m pydoc open

python -m pydoc raw_input

python -m pydoc argv


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.


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.


python -m pydoc -k/p/g/w <name>


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号