Bad auto completion with python on pydev? - python

I began learning and loving python about a month ago. Dive into python, django and now Tornado is the path i followed during this time.
I chose pydev as an IDE since it seems to be the most up to date and i wanted to come back to eclipse since i'm using Netbeans for php and Java.
My question is the following:
When i write classes in php or java i declare my methods and properties. I instantiate them somewhere else and use them. The autocompletion works great for java and php but with python, it seems to be always suggesting me a bunch of garbage and never the real object's methods from the class i instantiated.
Is it the same for you ? Is it a limitation from pydev ? Am i doing something wrong ?
Thank you in advance for pointing me in a direction.
Matthieu.

First make sure your interpreter is set up correctly.
Window | Preferences | Pydev | Interpreter - Python
I use cpython on linux so my interpreter is
cpython /usr/bin/python25
Under Libraries, make sure all the standard PYTHONPATH stuff is in there:
System Libs
/usr/lib/python2.5
/usr/lib/python2.5/site-packages
/usr/lib/python2.5/wx-2.8-gtk2-unicode
/usr/lib/python2.5/lib-tk
/usr/lib/python25.zip
etc....
You can also add any non standard paths here by clicking New Folder.
Do not add paths to your own source code though. These should come in when you configure a pydev projec, select a "src" folder and start making modules, see here.

Well, as you didn't say what 'garbage' is showing, it's a bit hard to guess, but I believe you mean the __hash__, __str__, etc from the object class (is that it?)
If that's the case, this has been dealt in the current nightly build (the '_' methods will still appear, but with lower priority, so, the methods you're probably more interested in are at the top)

Pycharm (http://www.jetbrains.com/pycharm/index.html) is much better than Pydev for auto completion, among other things.

Related

Intellisense for Ruby, Ruby on Rails, Python

Are there any intellisense options for languages like Ruby, Ruby on Rails, Python, etc?
This could include an IDE, if necessary. I'm looking for something like Visual Studio's c# or Eclipse's java intellisense.
Sure are!!
jetbrains has full line of ide's.
PyCharm and RubyMine
http://www.jetbrains.com/ruby/
Because of the dynamic nature of these languages, implementing things like auto-completion is quite difficult, and only works for some cases.
Examples for Python: pydev (eclipse plug-in), rope (this is a refactoring library that can easily be used into emacs),anyting with ipython (again, an emacs mode).
Anyways, don't expect them to be as powerful as the tools you have for Java or C#.
Rope for example, does a bit of type inference to figure out parameter types in order to give you completion suggestions. This might take an awfully long amount of time for big codebases, thus making the feature useless on such codebases.
anyting with ipython on the other hand actually spawns a background python process that imports your current module and any modules it references, and does runtime checking on entities (classes, functions, global variables...) in those modules. Because it doesn't do type inference, it can't give you any auto-completion suggestions for variables passed as parameters or local variables.
My vim setup uses the supertabcomplete, snipmate, and python-mode plugins for mostly intellisense completion.
It's windows centric, because that is what I develop on, but just change the paths in the vimrc file after cloning and you should be up and functional.
Sublime Text 2 also supports this to a limited extent. Auto-completion is very difficult for dynamic languages, so this will display recently use variables/methods, and anything else that is nearby that matches the fuzzy text filter.
Use vim with dot files which includes syntax highlight, smart indentation, auto-complete for Ruby among other features. Although it had been worked for MacOS, but you can easily adapt to your OS if you're using other.
Another option includes Aptana for Eclipse or Jetbrains RubyMine. So try all the solutions and decide what best fits your needs.

Experienced Python programmers (ESPECIALLY former php programmers) : How do I debug python?

In PHP, it was extremely easy to start hacking away and figuring out what was going on on a page. Just throw in a bunch of echos and print_r's and that was about it. It appears that this technique is not working for me in python. I am getting practice by hacking around in a python photo upload module, and when a photo is uploaded, it creates 3 different size photos. I found the code that does this, but I want to see the state at that particular moment. I tried doing a "print" on the size variable, but it did not show up in my browser.
I guess a more straightforward question would be, is it "pythonic" do debug using the browser ( equivalent to echo's and print_r's in php ), or is this what the python console is for? Thanks!
Use the logging module rather than printing stuff to stdout.
Using the interpreter in interactive mode is a great way to try out code, and pdb is very useful for real debugging.
It's "pythonic" to do debugging using the pdb module.
But really, if you're just "hacking around", then I suggest messing around with an interactive interpreter interface, especially one that supports autocompletion (Python itself comes with IDLE right out of the box).
You need to learn how to use a debugger ;) Hacking with prints is cool for simple php, but you can save a lot of time in higher languages with a debugger.
As mentioned, PDP is a place to start http://docs.python.org/library/pdb.html
As others have mentioned PDB, I'll take the opportunity to sing the praises of Eclipse using the pydev plugin, which is absolutely fantastic. IDLE is also well worth a go. Both of these IDEs allow you to step through code, inspect variables, auto-complete, etc. etc.
http://pydev.org/
Download Eclipse then use the Software Updates menu to add in PyDev.
http://pydev.org/updates
PyCharm from JetBrains is as good as all their other products. It has an integrated debugger and lots more.

How do you get Intellisense for Python in Eclipse/Aptana/Pydev?

Does anyone know how to get an intellisense like functionality (better than default) in eclipse for python development? I am using Eclipse 3.5 with aptana and pydev and the interpreter is python 2.5.2
You are probably never going to get something as good as intellisense for python. Due to the dynamic nature of python, it is often impossible to be able to know the type of some variables.
And if you don't know their types, you can't do auto-complete on things like class members.
Personally, I think the auto-complete in PyDev is pretty good, given the nature of python. It isn't as good as for Java and probably won't be, but it sure beats not having anything.
Having said that, I haven't tried if PyDev is able to use the parameter types you can specify in python 3.x. Otherwise, that might be an improvement that could make life a little easier.
Update: Got curious and did a quick test, Looks like optional type information in python 3 is not used by PyDev.
I'm using eclipse 3.6 and pydev with python 2.6 and it's the best one I've tested up to now. I didn't try 3.5 so not sure if it's the same as yours but I think it autocompletes well compared to others I tried but I didn't try any of the paid ones.
In Aptana I added the reference to the .egg file to the system PYTHONPATH in Preferences menu. I am not sure if this works for every library out there.
Preferences --> PyDev --> Interpreter Python --> Libraries tab on the right.

Python IDE that you can highlight a method/class and jump to its definition

I'm trying to use textmate, but I find it hard to navigate a project with it.
I admit I probably just don't know the the IDE well enough.
Is it possible to highlight a class or method and jump to its definition?
I am not sure that I understood you question, but if you look for an IDE for Python I would strongly recommand you have a look at PyDev
It's by far the most feature-rich IDE for Python and it has a really active development team. And did I mention it's free and open source?
Wing IDE is an excellent IDE for python.
I too have been looking for an IDE that makes this sort of thing easy.
About two hours ago I downloaded Pycharm and it has blown me away. This may be the coolest IDE I have ever used, for any language. So far it seems to do everything that big IDEs like VisualStudio or Eclipse do (for many languages), only without the learning curve or resource consumption of those monsters.
It does exactly what you are asking... just right-click on any class, or a method, or pretty much anything else, Select "Go to Implementation" (or Declaration), and up it pops in a new tab.
So many other amazing slick features too... just try it!
There's a 30 day trial and after that it's pretty reasonable (like $29 for academic, $100 for individual, and $200 for a commercial team. Oh and FREE if you have a bona fide OpenSource project that's been actively worked on for at least 3 months.)
(I apologize if this sounds like an advertisement. I can assure you that it's not. I'm just kind of... obsessive... about IDEs, and very frustrated that so few of them meet my standards. I will revise this if I find any "caveats" but so far, so good.)
If you're asking about IntelliJ IDEA, Python is only available for the commercial version.
If you're asking about a Python IDE, IDLE comes with Python already. I can also recommend Boa Constructor.
WingIDE if you can fork out some cash will do what you want all bundled up and with little to no configuration effort.
Otherwise Eclipse with Aptana's pydev is free, and does exactly that, plus a lot more (ctrl+click pretty much anything for redirection and a lot of other useful things like pyc removal etc.).
Navigation problems though are usually symptomatic of more than just lack of tools. A decent structure to your projects and a version control system (even if you work locally and solo) would go a long way helping to address that.
I'm not sure about what functionality is available in textmate but would a simple search work? i.e. Ctrl+F with the query "def function" including the def part so you find the definition instead of a call?
I'm a fan of pyscripter http://code.google.com/p/pyscripter/. Has those features and more (and a regex checker!)
Open source of course.
Aptana Studio 3.0
The PyDev team is now operating under the auspices of Aptana, which makes Aptana Studio 3 - an Eclipse customisation - preferable to the 2-step process of first downloading Eclipse, and then installing the PyDev extension.
Aptana comes pre-configured for Python (and others), and in addition features custom support for Django projects [including JavaScript support].
The product is fast and responsive, and features powerful meta-level functionality such as jumping to the definition of a callable, deducing object fields from init initialisation, module browsing, very good code completion, and more...
Thus far, out of Eclipse+PyDev, NetBeans Python Edition and Aptana Studio 3, based on relatively extensive personal testing, AS3 wins hands down.
Here's a small Bundle/Command for TextMate that can accomplish Python Jump to definition for 99% of cases:
FUNC="$TM_CURRENT_WORD"
DIR="$TM_PROJECT_DIRECTORY"
OUTPUT=''
# Define the class or function definition string that we're looking for.
FUNCDEF='(def|class) '$FUNC
# Find all files that contain FUNCDEF
FILES=(`egrep "$FUNCDEF" $DIR/* -r -l --include=*.py`)
#
# Look for a function declaration within a files contents.
#
# <file>
#
function lookup_function {
local line=`nl -b a "$1" | egrep "$FUNCDEF" | awk '{print $1}'`
if [[ "$line" -gt 0 ]]; then
# echo 'Jumping to --> '$1':'$line
mate "$1" -l "$line"
exit 0
fi
}
# Iterate files
for file in ${FILES[#]}; do
echo $file
lookup_function "$file"
done
# Nothing found
echo 'Function '${FUNC}' was not found within the current project.'

New to Python. Need info on the environment for it

I'm a complete newbie to Python. I've worked on PHP/JavaScript earlier but starting today I'm moving onto Python. I have no idea about the environment needed for it. I could use some suggestions on it for me to get started.
Under Unix, Emacs is a good choice, to which I always come back, because it is convenient to have a single editor for everything, and because it's open source.
What is best for you depends on your past experience with IDEs. I'd say: stick with what you've been using, or take this opportunity to try an even better IDE.
Note: Python comes with Idle, which is a very simple (if limited) IDE.
Be sure to check out IPython. It's an enhanced interactive python shell with a bunch of useful features such as Tab-Completion using introspection (eg, type "my_object." to see a list of its attributes and methods), logging your interactive session to an executable python-file, defining macros, etc. The documentation page has a link to the tutorial as well as screencasts showing it in action.
On my mac/Linux machines, python came pre-installed. On windows I use both jython under the eclipse IDE and ActivePython with their IDE/eclipse.   With eclipse you'll want PyDev.
It all depends on what you are looking for and what you are already using.
For instance, if you are using a more 'simple' editor at the moment: as long as it's got Python syntax you've got the basics.
If you are used to e.g. Eclipse you can just continue to use that, combined with Pydev. Besides syntax highlighting you'll also get more fancy features to help you debug and refactor your code.
Personally I use Emacs with python-mode (and a few other modes to interface with Subversion and Git). In the past I used Vim which also worked quite well.
My advice would be to start out with your current environment as long as it has some rudimentary support for Python. Once you are familiar with the language, start exploring what your environment is missing and either add it or if you cannot, switch to an enviroment which does support the feature.
I use gvim with some plugin in order to have better support for python.
If you like IDE, look at wing IDE wich is the best I have tested so far. Especially the debuger included is really helpful.
The Python Beginner's Guide and the official Python Tutorial both seem like good places to start.
Geany is a good option for a Linux setup, it's intellisense isn't that great but syntax highlighting is good and it can compile your code directly from inside the editor, plus it handles other languages such as C/C++, PHP, Java etc... Eric is another popular choice as it's a full IDE and I know some people use Eclipse.
On windows I use Notepad++, but it's mostly because I like text editors instead of fully blown IDE's.
Reference wise Daniel's choices are very good places to start, also check out Green Tea Press who do free computer books, there are two Python choices on there but the "Python for Software Design" book hasn't yet been published properly although you can download the manuscript. The "How to Think Like a Computer Scientist" book is a good one and not as scary as it sounds.
IDLE is nice to try out things. Other tools that people like are Eclipse with the Pydev plugin which seems to work ok, although it has crashed a few times (Eclipse, that is) and NetBeans (which I haven't tried) but some people seem to like.
I can only help you if you're running a Mac. Download Xcode. I believe that Python 2.3 comes bundled with these development tools. Luckily enough, this is all you really need to get started, unless you want a newer version of Python.
All you need to do is open up Terminal and type python. You're done!

Categories

Resources