Is there a way to view Python API documentation from within code? - python

I am looking for a Python IDE that will display the API (standard or third party module) documentations as pop-up when I hover over the code e.g. in eclipse if you hover over the java code it will give you the details of the functions or class, given the API documentation is setup in your IDE.
I can access the documentation from the respective web-site, but this not what I am looking for.
I am using PyCharm Community version, but could not find a way to see the documentation as quick view, also trying to find out if they support such feature at all. Anyone has any experience with any other IDE that will support such feature other than Eclipse.
TIA.

Visual Studio Code Python extension has a feature that will show the documentation of a documented code. Juts type the name of a function or a class and choose the one you want from the autocomplete list.
For example:
Here on the right you can see the code documentation. You can scroll down in that window to see all.
Hope this was helpful.

Related

Seems my pylance having issue with autocomplete third party module's method

I am trying to switch the editor from Pycharm to Vscode somehow.
But some aspect of autocomplete isn't working in vscode I guess.
Specifically, when I want to utilize autocomplete dealing with BeautifulSoup module,
and want to see autocomplete in deeper property,
autocomplete works properly in Pycharm, where as vscode,
shows nothing.
I roughly know it may be a problem with Pylance extrapaths something
but I could'n figure out how.
I tried some features in setting.json like adding python language server to pylance,
or some kinda of pyright plugin hoping more delicate function but didn't get it.
Can I get some direct info about this matter?
The same problem exists on github and has been closed.
Beautiful soup needs to add type stubs for this to work.
You could suggest developer updating the package on bs4.

Is it possible to change the way PyCharm displays the OpenCV documentation?

PyCharm (PY-193.6911.25, macOS 10.15.4) doesn't correctly display the OpenCV documentation.
More concretely, this is the result.
As you can see, it's a mess. Is it possible to fix this? I installed OpenCV with pip.
After googling a lot I ended up thinking there is no easy solution but... there actually is!
What i did is:
Push CTRL Q
Scroll down to the trippledot and click open source.
Push CTRL+R(replace)
replace '. ' to ''
Now docstring looks like this:
Definately not perfect, but i think it looks a bit better.
Additionally i added this as external documentation:
https://opencv-python-tutroals.readthedocs.io/en/latest/search.html?q={element.name}&check_keywords=yes&area=default
So it brings up a cv2 'tutorial'...
In PyCharm 2020.1.1 professional edition with Python 3.7, the following warning is displayed for the cv2 docstring
You need configured Python 2 SDK to render Epydoc docstrings
Epydoc is a tool for generating API documentation for Python modules, based on their docstrings.
Pycharm can't render Epydoc docstrings
The suitable interpreter is looked up among those configured in the IDE (it has to be Python 2 since Epydoc package itself hasn't been ported to Python 3 yet). In other words, you need to set up it once so that it showed up on the list at Settings | Project: ... | Project Interpreter | Show All... -- it doesn't need to be actually used in any project. Is it true in your case?
The problem is that it's not really Epytext. OpenCV uses Doxygen for documentation that we don't support and also confuse with Epytext because of the similarity of tags. There is an open issue about it.
Doxygen is confused with Epydoc and displayed as free text (not preformatted)
I'm afraid this particular feature of PyCharm is not really extensible at the moment. Besides, displaying of documentation, injecting references to symbols inside it, completion of available tags and generation of documentation stubs -- everything is tied very closely to the fact that in Python code documentation is normally provided via designated string literals, not comments. The highest level API you can plug into to provide custom documentation source for Quick Documentation popup/tool window is com.intellij.lang.documentation.DocumentationProvider if you register yours before the default one with ID pythonDocumentationProvider. But it will cover only rendering, everything else will need to be written from scratch.
The official resolution is we don't support that

Autocomplete for Automation objects in VS Code and Python

I have the Python Extensions for Windows installed. Within the PythonWin IDE I can get autocomplete on Automation objects (specifically, objects created with win32com.client.Dispatch):
How can I get the same autocomplete in VS Code?
I am using the Microsoft Python extension.
The Python Windows Extensions has a tool called COM Makepy, which apparently generates Python representations of Automation objects, but I can't figure out how to use it.
Update
Apparently, the Microsoft Python extension uses Jedi for autocompletion.
I've filed an issue on the extension project on Github.
Note that in general I have Intellisense in Python; it's only the Intellisense on Automation objects that I am missing.
Review
I have confirmed your problem in VSCode, although it may be possible IntelliSense works fine. Note Ctrl+Space invokes suggestions for a pre-defined variable:
However, there does not appear to be public attributes available for win32com.client by default. This may be why IntelliSense does not appear to work.
Test
Having installed win32com for Python 3.6, I have confirmed the following code in Jupyter notebook, IPython console and the native Python REPL:
import win32com.client
app = win32com.client.Dispatch("Word.Application")
len(dir(app))
# 55
[x for x in dir(app) if not x.startswith("_")]
# []
This issue of hidden attributes is not a new. Please confirm this test in another environment/IDE. It may be your environment or particular version of PythonWin pre-loads certain variables in the global namespace.
Verify the following:
The Python extension is installed
A Python interpreter is selected
A Python file is selected; this starts up the Python server
References
Post by the extension's creator for troubleshooting autocompletion issues.
Thread on how autocompletion works via PyScriptor
I don't think that the example you show with PythonWin is easily reproducible in VS Code. The quick start guide of win32com itself (cited below) says, its only possible with a COM browser or the documentation of the product (Word in this case). The latter one is unlikely, so PythonWin is probably using a COM browser to find the properties. And because PythonWin and win32com come in the same package, its not that unlikely that PythonWin has a COM browser built in.
How do I know which methods and properties are available?
Good question. This is hard! You need to use the documentation with the
products, or possibly a COM browser. Note however that COM browsers
typically rely on these objects registering themselves in certain
ways, and many objects to not do this. You are just expected to know.
If you wanted the same functionality from the VS Code plugin a COM browser would have to be implemented into Jedi (IntelliSense of the VS Code plugin).
Edit: I found this suggestion, on how a auto-complete, that can find these hidden attributes, could be done:
These wrappers do various things that make static analysis difficult,
unless we were to special case them. The general solution for such
cases is to run to a breakpoint and work in the live runtime state.
The auto-completer should then include the complete list of symbols
because it inspects the runtime.
The conversation is from an mailing list of the python IDE wingwide. Here you can see, that they implemented the above mentioned approach:
I think your problem is related to defining Python interpreter.
Choose proper Python interpreter by executing python interpreter command in VS Code command palette by pressing f1 or ctrl+shift+p key.

Python Tools for Visual Studio - tell the IDE what type a parameter will be

I just started using Visual Studio 2015, and I really like it, especially the code completion features. Right now I'm writing some simple Python code to draw an object on a Tkinter Canvas:
def draw(self, can):
""" can is a Tkinter canvas on which this node will draw itself. """
can.<something>
This being Python, nowhere in the actual code is it indicated that "can" is going to be a Canvas, so VS can't autocomplete or suggest anything after I type "can." Is there a way I can tell Visual Studio that can will be of type tkinter.Canvas?
Yes, you can use an assertion statement. This will trigger VS autocomplete settings. It's not the most beautiful way to do it, but I think right now that's the best option.
assert isinstance(can, tkinter.Canvas)
Take a look at this answer for more.
I'm going to preface this by saying I haven't used Python Tools for Visual Studio (although I use Visual Studio for C# and it's a great IDE) and so this isn't a direct answer for your question. However, I'm guessing from "I just started using Visual Studio 2015" that you might be checking out different tools, so maybe this can still be helpful to you.
I started using PyCharm a few days ago since I plan on doing some serious Python work soon, and I have to say it's pretty phenomenal in my opinion.
To relate back to your question, you have at least a couple ways of letting PyCharm infer the type of your parameters.
Method 1: Python 3 Type Hints
If you're using a Python 3.5 interpreter, you can help PyCharm infer the types of parameters by providing type hints in your code.
Method 2: Docstrings
Alternatively, you can let PyCharm infer types by providing a docstring with the function that contains type information. In the example below, I'm using documentation in reStructuredText format.
The advantage of doing it this way is that it works whichever interpreter you're using.

PyQt documentation

I have installed PyQt GPL v4.6.2 for Python v3.1 and Qt by Nokia v4.6.0 (OpenSource), but the documentation in PyQt is not coming up. Example docs are all blank, too.
Would anyone mind writing a step-by-step guide on what links to visit and what procedures must be executed in order to get text to come up for the PyQt documentation?
Edit: The programs are running on Windows, and the documentation is not coming up in PyQt GPL v4.6.2 for Python v3.1 > Examples > PyQt Examples and Demos and PyQt GPL v4.6.2 for Python v3.1 > Assistant. What needs to done to let both programs access the docs?
Some out of date answers here. Best resources are:
The Reference Guide
and
The Class Reference Guide
Not sure about the standalone docs, but have you also looked at (this post is a cw, so feel free to edit):
PyQt's Classes, adapted from the documentation provided with Qt4.
and
GUI Programming with Python: QT Edition?
The last one has some really deep and helpful (at least to a novice I think) advice (for example: Python Objects and Qt Objects) while being a free book.
Whenever I need to look at documentation, I just search Google for the specific widget I am interested in. For example: QTreeWidget. Sometimes you get an older version of Qt, but if you click the "similar" link in the search result, you can pretty much always find the page you are looking for.
The PyQt documentation is exactly as provided on the website, and as
included in the installer. It is not integrated with Assistant (it will be
in a future version). If you want to use Assistant then you can use the Qt
documentation instead (a lot of people do) and translate between C++ and
Python as you read it.
If you installed the Qt documentation, you should have an app named Assistant. This is a simple-minded browser for a local copy of the Qt doc as found at doc.qt.nokia.com. It is written for C++ but the mental translation to Python is not difficult, and it is nicely formatted and richly cross-linked. I keep Assistant running all the time I'm coding in PyQt4 and find it very helpful.
The PyQt doc, as given at www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/classes.html, is merely this same Nokia text with its formatting and many of the internal links stripped out and edited to python class and function syntax.

Categories

Resources