I'm looking at various IDEs for python. Looking at the official list the IDEs are categorized based on 'introspection based code completion'.
What does introspection based code completion mean?
Thanks.
It means the IDE uses introspection to figure out what methods and variables are accessible from a given object, then allows quick code completion, usually by providing a list of options after you type a period following a symbol.
Here's an example if WingIDE Pro inaction. Forgive the hastily thrown together image.
You can see that arg1 is being shown as 1 in the first example, as well as the helper showing that it is probably an int.
In the second part, you can see that the IDE is looking through the docstrings for what the method get does, in the requests module.
The second image below shows that the IDE can 'auto-complete' code for you, including showing what it does.
Related
Can I use index.d.ts to enable custom code documentation & auto-completion for Python code as we do in JS? if so, how? If not, is there any equivalent for Python?
Yes, there have been various additions to Python over time that allow you to do so.
As mentioned in the comments, https://www.python.org/dev/peps/pep-0526/ and https://www.python.org/dev/peps/pep-0257/ cover this in part.
See also the documentation on type hints here https://docs.python.org/3/library/typing.html
Note that if you wanted to know how to provide type hints for a very specific example, you should have probably included some sample code that needed the hints, but hopefully the above helps.
For example, when i use matplotlib as plt, a possible statement is like below:
plt.plot(x,y,color='blue')
so how can i get what arguments like 'color' i can pass to the 'plot' function, and what is the proper values for that argument?
Especially when i use some modules.
thanks for any answers.
I'm a little disappointed that this post is being downvoted because I think it's a very legitimate question. In particular, I appreciate that you asked not what the answer was but instead how you could find it for yourself in the future.
Exploring Local Python Documentation
Python has a very robust built-in documentation system as well as a very active and supportive community. At any point in time, you can use the help function to examine a particular object that you want more information on - this will pull up the documentation for that object. In your example, you could do something like:
help(plt.plot)
to pull up the documentation for the matplotlib.pyplot.plot function. Outside of a running Python process, you can use the pydoc command line tool to read and explore that same documentation. Something like:
$ pydoc matplotlib.pyplot.plot
Running that in the shell will display the same documentation as the help command example.
Writing Documentation
As a good citizen of the Python ecosystem, you'll naturally want to document your own code. This is done pretty simply by adding a docstring to the top of a function, class, or module. Docstrings are denoted with a triple quotation mark """, seen in the examples below:
"""This module contains some example classes and functions"""
class MyClass(object):
"""MyClass does some things"""
pass
def my_function(a):
"""Calculates the sum"""
return(a)
There are many different documentation styles that people prefer, so what you choose is up to you. Though I would recommend the official docstring standards outlined in PEP 257.
Finding Online Resources
It's also often useful to take advantage of online documentation and resources. The official Python documentation includes all of the builtin documentation for the standard libraries as well as a tutorial for developers who are new to Python!
As it seems that you're relatively new to the ecosystem yourself, here's some more resources that you might find useful:
Learn Python the Hard Way
CodeAcademy has a Python track
StackOverflow, obviously
What is the optimal way to get documentation about a specific function in Python? I am trying to download stock price data such that I can view it in my Spyder IDE.
The function I am interested in is:
ystockquote.get_historical_prices
How do I know how many inputs the function takes, the types of inputs it accepts, and the date format for example?
Just finding documentation
I suspect this question was super-downvoted because the obvious answer is to look at the documentation. It depends where your function came from, but googling is typically a good way to find it (I found the class here in a few seconds of googling).
It is also very trivialy to just check the source code
In order to import a function, you need to know where the source file it comes from is; open that file: in python, docstrings are what generate the documentation and can be found in triple-quotes beneath the function declaration. The arguments can be inferred from the function signature, but because python is dynamically typed, any type "requirements" are just suggestions. Some good documenters will provide the optimal types, too.
While "how do I google for documentation" is not a suitable question, the question of how to dynamically infer documentation is more reasonable. The answer is
The help function, built in here
The file __doc__ accessible on any python object, as a string
Using inspection
The question is even more reasonable if you are working with python extensions, like from external packages. I don't if the package you specifically asked about has any of those, but they can be tricky to work with if the authors haven't defined docstrings in the module. The problem is that in these cases, the typing can be rigidly inforced. There is no great way to get the tpye requirements in this case, as inspection will fail. If you can get at the source code, though, (perhaps by googling), this is where the documentation would be provided
I like using IDEs when writing stuff in Python or other languages because modern features like call tips or code completion make things much easier. Since Python is a dynamically typed language there is, of course, no way to provide these features for variables such as function arguments. This causes the modern features to disappear, which results in everything being cumbersome and time consuming, because I usually have to reference class definitions to double check the correctness of what I'm accessing.
Are there any Python IDEs that have support for code completion by suggesting an expected type for a variable? For example, if variable x is expected to be a str class, I would like to be able to suggest that x's type is str and have code completion enabled for that class.
I read that PyDev might be able to do this, but I really don't want to use it because Eclipse. My preferred IDE is PyScripter, but I'm fairly certain that it can't do this.
Try PyCharm, supports code completion, on-the-fly error highlighting, auto-fixes etc.
http://www.jetbrains.com/pycharm/
I am currently using https://github.com/fgallina/python.el + ropemacs, but I am missing module browser: separate buffer that outlines names defined in the current module (list of classes with their methods). Google says that there are OO-browser and emacs-code-browser, but they looks outdated and I can't find any mentions about this libs in any of popular emacs + python tutorials. What should I use to achieve easy navigation across the module?
I think ECB (Emacs Code Browser) is worth a try. I don't use it all the time but it can be very handy. Especially useful is the "ECB Methods" window which displays an outline of all members of a module.
Here is a screenshot with the ECB Methods window in the lower left corner: http://dev.pocoo.org/~gbrandl/emacs2.png.
See also http://www.emacswiki.org/emacs/EmacsCodeBrowser.
Maybe occur can be helpful in this case. For example, if you want to list the defined functions: M-x occur RET def RET should visit a buffer where the def's are listed.
M-x speedbar might get you what you want.