This has got to be a silly question... but googling didn't actually help. Extra kudos for pycharm enabled answers. :)
I need a simple little UDP echo server (spare me the twisted advertisements please, this is a throw away thing, I just need to use it to peek at what a little embedded gadget is broadcasting). So I find section 21.21 of the Python 3 reference manual. It's a simple example that does exactly what I want.
But the same document also mentions a DatagramRequestHandler class. But there's no further explanation on how that differs from its parent class, or what it provides. I had really hoped that when I imported said class, that pycharm would somehow display a helpful popup for it, but I'm unable to discover such a thing.
Do I assume correctly, that I should just go find the source in my (macosx) install and look directly at that? is there a pattern for how people do that? My actual question here, is actually less about DatagramRequestHandler, and more about the general pattern, because this obviously will happen else where in the base docs.
(context: my traditional experience is with Smalltalk image based environments, where you can always just jump from class to class to class, and navigate quickly from application code all the way to the bowels, as a sort of exploratory way of learning and discovery)
There is an option to navigate to the declaration of the name under your cursor, Navigate->Declaration (shortcut CTRL+b in my keymap).
If you have such a question there are three things to do:
google it (eg. python DatagramRequestHandler)
use the help function in a interactive python session. eg.
import socketserver; help(socketserver.DatagramRequestHandler)
look into the code
Most of the time the first option is enough (this time I found only something in german). The result from the second option is in this "example" not so interesting or useful. So you have to use try third option.
Related
I need to find global caret position in Linux. The problem is similar to this one for Windows. Do you guys have any idea?
More information:
I am trying to make input method for a certain Indic language. I am using IBus libraries in Python. I need to create something like the lookup table found in IBus but my requirements are such that I decided its better if I make the whole thing again using tk (or something). The link in the question solves this problem for windows where a tooltip follows the text caret. So I need something just like that but for X-Windows.
There is no such thing as a caret position in X11. While the older UIM framework did a fairly good job of displaying the input method UI near the cursor position, this failed often enough that it was abandoned.
You might want to take a look at the SCIM framework. Note that it is usually preferred to hint the application at the completion state rather than provide a separate editor, as this gives a more seamless integration.
I figured it out! All I had to do was create a method in my IBus engine class (sub class of IBus.Engine) called do_set_cursor_location which handles the signals created when position of the caret changes. Here is more from IBus manual: The "set-cursor-location" signal.
That means the problem is solved for now, although I certainly don't know what is happening under the hood.
Thanks guys.
Python is a relatively new language for me and I already see some of the trouble areas of maintaining a scripting language based project. I am just wondering how the larger community , with a scenario when one has to maintain a fairly large code base written by people who are not around anymore, deals with the following situations:
Return type of a function/method. Assuming past developers didn't document the code very well, this is turning out to be really annoying as I am basically reading code line by line to figure out what a method/function is suppose to return.
Code refactoring: I figured a lot of code need to be moved around, edited/deleted and etc. But lot of times simple errors, which would otherwise be compile time error in other compiled languages e.g. - wrong number of arguments, wrong type of arguments, method not present and etc, only show up when you run the code and the code reaches the problematic area. Therefore, whether a re-factored code will work at all or not can only be known once you run the code thoroughly. I am using PyLint with PyDev but still I find it very lacking in this respect.
You are right, that's an issue with dynamically typed interpreted languages.
There are to important things that can help:
Good documentation
Extensive unit-testing.
They apply to other languages as well of course, but here they are especially important.
As far as I know If code is not documented at all and the author isn't around anymore it's up to you to find out what the ode actually does.
That's why people should always stick to certain guidelindes that can be enforced by stylecheckers like pep8. https://pypi.python.org/pypi/pep8
Comments and docstrings should be included in every method to avoid such situation you're describing. http://www.python.org/dev/peps/pep-0257/#what-is-a-docstring
Also unittests are very helpfull for refactoring since you can check if you broke something with the click of a button. http://docs.python.org/2/library/unittest.html
hope this helps
Others have already mentioned documentation and unit-testing as being the main tools here. I want to add a third: the Python shell. One of the huge advantages of a non-compiled language like Python is that you can easily fire up the shell, import your module, and run the code there to see what it does and what it returns.
Linked to this is the Python debugger: just put import pdb;pdb.set_trace() at any point in your code, and when you run it you will be dropped into the interactive debugger where you can inspect the current values of the variables. In fact, the pdb shell is an actual Python shell as well, so you can even change things there.
I've looked at most of the IDE's out there. I've set up vim to use autocompletion and I'm using it right now. However, I can't seem to get it to work like Visual Studio with .NET. Autocompletion seems to work only in certain cases and it only shows methods and not what parameters they take. It's pretty much unusable to me.
What I'm after is a pop-up that will show me all methods available and the parameters they take. Pretty much the feel of VS2010 when you're programming .NET.
You won't get the kind of autocompletion in a dynamic language like Python that you get in more explicitly typed languages. Consider:
def MyFunction(MyArg):
MyArg.
When you type the "." in MyArg., you expect the editor to provide a list of methods with arguments. That can't happen in Python because the editor has absolutely no way of knowing what type (or types) MyArg could possibly be. Even the Python compiler doesn't have that information when it's compiling the code. That's why, if you put MyArg.SomeNonExistentFunction() you won't get any kind of error message until runtime.
If you wrote something like:
def MyFunction:
MyObject = MyClass(SomeArg)
MyObject.
then a smart enough editor can supply a list of methods available after that final ".".
You'll find that those editors that are supplying autocomplete "sometimes" are doing so in cases similar to my second example, and not doing so in cases similar to the first. With Python, that's as good as you can get.
I've been using Eclipse with the PyDev extension for some time now. The auto-completion there is really quite impressive, I highly recommend it.
Gedit has a developer plugin which tries to do some syntax completion. For reasons already mentioned, it doesn't work very well. I found it more annoying than helpful and disabled it after a few weeks trial.
ipython's new Qt console has tab completion and you can have some tooltip sort of popups with syntax help and docstrings. See screenshot below for example..
But as most people have already pointed out, this kind of thing you are asking for is really more appropriate for less dynamic languages.
f = open(filename, 'r')
strings = f.read().lower()
I want a python editor/ide that works like visual studio. In the above after typing 'f.' it shows me the list of available functions and their documentation(DO NOT WAIT FOR ctrl-space). Just like visual express C#. Also preferably it shows autocomplete lists of all variables as well. Is there such an editor?
I have gone through several suggestions - eclipse , vim , emacs , pyscripter, komodo etc etc. Tired of trying. finally asking.
Help me out.
I have checked similar questions, none answered my query.
Try to take a look at PyCharm. It not open source but it is quite cheap and powerful IDE:
http://www.jetbrains.com/pycharm/
http://www.jetbrains.com/pycharm/features/index.html
Code completion for keywords, classes,
variables, etc. — Ctrl+Space. Editor
suggestions are context-aware and
suggest most appropriate options.
Quick definition / documentation view
— see the object definition or
documentation in-place without losing
your context
You can try Netbeans. It is free. Some of its features -
It shows a list of functions and their documentations as well as variables but on Ctrl+Space. (I don't know why you don't want to hit Ctrl+Space, otherwise every time you start writing something, you will be disturbed by a popup.)
It also underlines unused variables, plus the other usual things like syntax highlighting, matching closing brackets, etc.
You can easily change the name of variables within a function/class using the refractor.
You can find usages of a particular names within your project
You can view all your classes, their methods and attributes, functions and global variables at a glance using the navigator.
It has a project manager
You can debug your project.
(whatever else you can possibly think of.)
It has lots of other features... I can't name them all here.
It is the best opensource IDE !
I can confirm that wingide code completion works like that. I tried the example you have here and it worked
I use Pydev, after Vim it speeds a lot! You can quickly navigate your project tree, in tabs you open necessary files, also inline watching of class/method definition, you can even 'jump' to that file. Also you can mark project as 'Django project', after setting python paths it really helps make less mistakes and code quickly. Also I've very much benefited multi-file search/replace. Recommend it! :)
Note: If you use Linux, replase OpenJRE with binary from Oracle's site. Otherwise there'll be craches.
I want to learn it but I have no idea where to start. Everything out there suggests reading the libpurple source but I don't think I understand enough c to really get a grasp of it.
There isn't much about it yet... the intro, the howto, and the sources (here browsing them online but of course you can git clone them) are about it. In particular, the tiny example client you can get from here does have some miniscule example of use of purple's facilities (definitely not enough, but maybe it can get you started with the help of some 'dir', 'help' and the like...?)
Not sure how much help this will be but based on information from here, it seems like you just install python-purple and import and call the functions as normal Python functions.
Can't help you with a concrete example as I decided to use something else. However, one of the first things I wanted to do after I cloned the repo was remove the ecore dependency. Here's a patch submitted to the mailing list to do just that: https://garage.maemo.org/pipermail/python-purple-devel/2009-March/000000.html
Incidentally, if you're looking for AIM take a look at twisted.words. For Yahoo, trying getting the source for curphoo or zinc (both are console YMSG clients). For GTalk/Jabber, I've had good experiences with xmpppy.