Results 1 to 8 of 8

Thread: Python code completion

  1. #1
    Join Date
    Oct 2008
    Beans
    112

    Python code completion

    I'm new to Python and have mostly programmed under Windows with Visual Studio. Now since moving to Linux, my blinkers have been lifted, so i'm now more inclined to use dedicated tools for the job in hand.

    What i'm looking for is a Python editor/ide/whatever with the best code completion and call tips. Having tried just about everything in the repos, i seem to be going round in circles. These are my findings...i'd LIKE to be disproved:
    • Geany is nice but there's no code completion for Python.
    • Gedit is also nice and has some plugins for Python, but code completion is poor.
    • SPE, IPython and BOA have reasonable code completion but only in the Shell.
    • IDLE also has Shell based code completion but looks pretty crap on Ubuntu.
    • Vim and Emacs. WHY? Jesus, i never realised that a simple text editor could be made so difficult to use!
    • I've also tried DrPython, Eric4, Pida, PyPe and Eclipse/PyDev. The main let downs were lack of (or poor) code completion/call tips.


    My reasons for not wanting the Shell style editors is because it runs my code real-time and that's no good when you're trying to write classes, functions, timed code, etc, etc. But perhaps i have misunderstand the whole Python and Shell thing...i'm assuming that the sole purpose of a Shell is for quick n' dirty code testing?

    The one i haven't mentioned is Editra...and that's because it is the one i am currently using. What i'd *like* to see, is my available options every time i press '.' or '(' or 'ctrl+space'...but in reality i know that this is no simple task for a language like Python. I do know that Editra executes the code in order to find code completions and the developer has 'perfect' code completion at the top of his 'to do' list.

    So yeah, what i'm asking is: are there any editors/ide's that have BETTER code completion than Editra?
    Last edited by pokerbirch; December 28th, 2008 at 09:13 PM. Reason: smelling pistakes

  2. #2
    Join Date
    Feb 2008
    Location
    52°38'41.6"N/1°19'43.6"E
    Beans
    Hidden!

    Re: Python code completion

    I too have had most experience with VS, due to work...

    I use PyDev with Eclipse for my fun coding, and the code completion can be annoyingly ****...i.e. just when you want help none is available

    I tend to have a browser window open to python docs where I look up libraries etc for help as and when

    I'll be keeping an eye on your thread with curiosity...good code completion would be a nice luxury
    Last edited by kaivalagi; December 28th, 2008 at 08:24 PM.

  3. #3
    Join Date
    Aug 2006
    Location
    60°27'48"N 24°48'18"E
    Beans
    3,458

    Re: Python code completion

    Eclipse + PyDev is the best I've used.

    When it comes to code completion with Python, you have to understand that you can't deduce types from Python all the time statically simply by studying source, because the types are not declared but exist only at runtime. So theoretically speaking this makes Python type resolution necessarily Turing-complete, because you must run any algorithm you have to know what types are present at runtime.

    Then again, duck typing reduces greatly the number of actual types you must deal with, so the general unavailability of code completion is not such a huge issue as it would be in static-typed languages like Java.
    LambdaGrok. | #ubuntu-programming on FreeNode

  4. #4
    Join Date
    Aug 2008
    Location
    OHIO
    Beans
    281
    Distro
    Xubuntu 9.04 Jaunty Jackalope

    Re: Python code completion

    I used WingIDE, to get full code completion it is not free but I like it and its code completion keeps getting better with each update...

  5. #5
    Join Date
    Oct 2008
    Beans
    20

    Re: Python code completion

    If you don't mind, consider buying Wing IDE. I have long been using 101 free version (No code completion) and Bought Personal Edition. I enjoy code completion now

  6. #6
    Join Date
    Jun 2007
    Beans
    692

    Re: Python code completion

    If you work an open source project written in Python you can get the professional version of WingIDE for free. I've been very happy with it. The code completion works great, as do the other neat features (debugger, source browser, integration with pylint and pychecker, lots of other good stuff).

  7. #7
    Join Date
    Oct 2008
    Beans
    112

    Re: Python code completion

    When i tried Eclipse + PyDev, it didn't seem to offer me anything more than Editra did...so i couldn't see much point in having a fat Java app and JVM when a 7Mb package could do the same. Mind you, i've learnt a lot more Python since i did that about a week ago.

    I quite like Editra. You can tell that the developer is a Python coder. The simple things like block (un)commenting, customizable syntax colouring + layout + views + etc, python plugins, 'run' button/key, etc, etc all make coding enjoyable. There's even a HTML generator which creates a web page with your code all nicely coloured to match your syntax settings.

    I've just been playing around with some http code and there are a couple of areas where Editra code completion fails. Here's the code:

    PHP Code:
    import urllib2
    import gzip
    from cStringIO import StringIO 
    # cStringIO faster than StringIO

    USER_AGENT 'Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.0.5) Gecko/2008121622 Ubuntu/8.10 (intrepid) Firefox/3.0.5'

    # build http req
    debug urllib2.HTTPHandler(debuglevel 0# 1 = on, 0 = off
    req urllib2.build_opener(debug)
    req.addheaders = [('Accept-Encoding''gzip'),
                      (
    'User-Agent'USER_AGENT)]
    # send http request
    try:
        
    resp req.open('http://www.whatismyip.com')
        
    # get response headers
        
    resp_headers resp.info()
        
    # check if gzipped
        
    resp_encoding resp_headers.getheaders('Content-Encoding')
        if 
    resp_encoding == ['gzip']:
            
    # decompress response
            
    buf StringIO(resp.read())
            
    gz gzip.GzipFile(fileobj buf)
            
    html gz.read()
            print(
    html)
        else:
            
    # data not compressed
            
    html resp.read()
            print(
    html)
    except:
        print(
    'HTTP ERROR'
    Details of code completion (roughly in line order):
    • typing 'urllib2.' shows correct completions throughout the document and typing '(' shows correct call tips for every function.
    • typing 'req.' doesn't include 'addheaders' as an option on the first call. Once it has been used once, it becomes available for the rest of the document. Call tips are not shown.
    • again, when typing 'req.', 'open' is not included in the list of completions. Unlike 'addheaders' above, this never gets added, even after you've used it. No call tips.
    • typing 'resp.' shows no completions at all. This remains for the entire life of the 'resp' object. No call tips.
    • typing 'resp_headers.' shows no completions at all. This remains for the entire life of the 'resp_headers' object. No call tips.
    • typing 'gzip.' correctly shows all completions.
    • typing 'gzip.GzipFile(' shows correct call tips.
    • typing 'gz.' correctly shows all completions.
    • typing 'gz.read(' shows correct call tips.

    I've probably missed a couple, but you get the general idea. I'm wondering if you guys could be kind enough to try this code in your editors of choice and report your findings? I'm particularly interested in seeing how PyDev and WingIDE compare to Editra's code completion.
    Last edited by pokerbirch; December 29th, 2008 at 12:53 AM.

  8. #8
    Join Date
    Jun 2007
    Beans
    692

    Re: Python code completion

    The results in WingIDE are the same, except for "req." always showing addheaders as a code completion option. I think the cases where you don't see completions means the type of the variable is ambiguous or not clearly defined in the current or imported modules.

    However, you can tell WingIDE how to treat variables it can't figure out using the assert keyword. For example:
    PHP Code:
    class TestDialog(gtk.Dialog):
        
    def __init__(self):
            
    gtk.Dialog.__init__(self)

    test TestDialog() 
    Referencing test.vbox, which is of type gtk.VBox, does not show any code completion options in WingIDE. However, doing this:
    PHP Code:
    class TestDialog(gtk.Dialog):
        
    def __init__(self):
            
    gtk.Dialog.__init__(self)
            
    assert(isinstance(self.vboxgtk.VBox))

    test TestDialog() 
    Will cause the code completion to show up correctly. This may be the case in other editors, too, so try it out.
    Last edited by imdano; December 29th, 2008 at 02:29 AM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •