Emacs for Python programming: module/class outline/browser - python

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.

Related

How can i know what parameters i can pass to a python function and what is the proper values?

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

BIOS like, interactive menu, for python text based game

I am writing a text based game in python and as you'd expect, it has many questions with multiple answers e.g. yes/no.
I have been been using the usual, input your answer, answering technique, but I was hoping to make it a bit more interactive in answering some options, such as the main menu. I do not want a full on GUI but is there some way to have something similar to, for example, the modern BIOS menu, where you use the arrow keys to navigate, and press enter to select?
http://www.washington.edu/lst1/help/computing_fundamentals/troubleshootingxp/img/bios.gif
Thanks for any reply's, whether it's possible or not!
P.S. I would rather not have to download any plugins etc, because I have to be able to use this at school where I cannot use them.
This is a rather open-ended question (not have to download any "plugins")? But what you want is the curses library, to which Python has an interface with its curses module. The Python docs provide a simple tutorial for using it.
There is also a library called Blessings which provides a nicer, more modern object-oriented interface to curses. I haven't tried it but it's well supported and looks pretty good.
Take a look at the Urwid library: http://excess.org/urwid/
(I know you'd like to not use an external module, but that means you'll essentially have to reimplement most of CURSES yourself, and that's a road you really don't want to take)

What is the System() import in Python

Long story short, a piece of code that I'm working with at work has the line:
from System import System
with a later bit of code of:
desc_ = System()
xmlParser = Parser(desc_.getDocument())
# xmlParser.setEntityBase(self.dtdBase)
for featureXMLfile in featureXmlList.split(","):
print featureXMLfile
xmlParser.parse(featureXMLfile)
feat = desc_.get(featureName)
return feat
Parser is an XML parser in Java (it's included in a different import), but I don't get what the desc_ bit is doing. I mean obviously, it somehow holds the feature that we're trying to pull out, but I don't entirely see where. Is System a standard library in Python or Java, or am I looking at something custom?
Unfortunately, everyone else in my group is out for Christmas Eve vacation, so I can't ask them directly. Thank you for your help. I'm still not horribly familiar with Python.
This isn't from the standard library, so you'll need to check your system (Python has plenty of introspection to help you with that).
You can tell as Python modules in the standard library use lowercase names as per PEP-8, or by searching the library reference.
Note as well that Python has it's own XML parsing tools that will be much nicer to work with in Python than Java's.
Edit: As you have noted in the comments you are using Jython, it seems likely this is Java's System package.
millimoose indicated the correct answer in his comment, but neglected to submit it as an answer, so I'm posting to indicate the correct answer. It was indeed a custom module built by my company. I was able to determine this by typing import System; print(System) into the interpreter.

What is "Introspection-based code completion"?

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.

What is the best way to sample/profile a PyObjC application?

Sampling with Activity Monitor/Instruments/Shark will show stack traces full of C functions for the Python interpreter. I would be helpful to see the corresponding Python symbol names. Is there some DTrace magic that can do that? Python's cProfile module can be useful for profiling individual subtrees of Python calls, but not so much for getting a picture of what's going on with the whole application in response to user events.
The answer is "dtrace", but it won't work on sufficiently old macs.
http://tech.marshallfamily.com.au/archives/python-dtrace-on-os-x-leopard-part-1/
http://tech.marshallfamily.com.au/archives/python-dtrace-on-os-x-leopard-part-2/

Categories

Resources