python

Python Table engine binding for Tokyo Cabinet

I am looking for python bindings for Table engine of Tokyo cabinet. I tried Pytc but can only find Hash and B-tree engine support. Is there any other bindings available? ...

Digital Image cropping in Python

Got this question from a professor, a physicist. I am a beginner in Python programming. I am not a computer professional I am a physicist. I was trying to write a code in python for my own research which involves a little image processing. All I need to do is to display an image and then select a region of interest using my mouse and f...

How to write meaningful docstrings?

Hello crowd, What, in Your opinion is a meaningful docstring? What do You expect to be described there? For example, consider this Python class's __init__: def __init__(self, name, value, displayName=None, matchingRule="strict"): """ name - field name value - field value displayName - nice display name, if empty will b...

Solution basis of underdetermined equation set in python

I have an underdetermined equation set (m equations of n variables, m smaller than n). As such, if it is solvable then the set of solutions are a linear space (if it is a homogenic set) or affine space (non-homogenic). Is there an easy way in Python (possibly with other libraries) to obtain this space - for example, a basis of which? T...

Store last created model's row in memory

I am working on ajax-game. The abstract: 2+ gamers(browsers) change a variable which is saved to DB through json. All gamers are synchronized by javascript-timer+json - periodically reading that variable from DB. In general, all changes are stored in DB as history, but I want the recent change duplicated in memory. So the problem is:...

Should I check the types of constructor arguments (and at other places too)?

Python discourages checking the types. But in many cases this may be useful: Checking constructor arguments. e.g. checking foe Boolean, string, dict etc. If I don't and set the object's members to the arguments it will cause problems later. Checking functions arguments. In properties. If someone sets a wrong value or different type, I ...

Do many Python libraries have relatively low code quality?

Edit: Since this question was asked a lot of improvement has happened in the standard Python scientific libraries (which was the targeted area). For example the numpy project has made a big effort to improve the docstrings. One can still argue if it would have been possible to address these issues continuously right from the start. I ...

Differential AJAX updates for HTML table?

I have a game on Google App Engine that's based on a 25x20 HTML table (the game board). Every 3 seconds the user can "move," which sends an AJAX request to the server, at which time the server rerenders the entire HTML table and sends it to the user. This was easy to write, but it wastes a lot of bandwidth. Are there any libraries, clie...

Evil code from the Python standard library

So, we have had this: http://lucumr.pocoo.org/2009/3/1/the-1000-speedup-or-the-stdlib-sucks. It demonstrates a rather bad bug that is probably costing the universe a load of cycles even as we speak. It's fixed now, which is great. So what parts of the standard library have you noticed to be evil? I would expect all the responsible peop...

How can I use C++ class in Python?

I have implemented a class in C++. I want to use it with Python. Please suggest step by step method and elaborate each step. Somthing like this... class Test{ private: int n; public: Test(int k){ n=k; } void setInt(int k){ n = k; } int getInt(){ ...

How to show the output of 'l' in python pdb after every command entered

I would like to have the output of the python pdb 'l' command printed to the screen after every command I enter in an interactive debugging session. Is there a way to setup python pdb to do this? ...

How can I access the current executing module or class name in Python?

I would like to be able to dynamically retrieve the current executing module or class name from within an imported module. Here is some code: foo.py: def f(): print __name__ bar.py: from foo import f def b(): f() This obviously does not work as __name__ is the name of the module that contains the function. What I would like...

python opens text file with a space between every character

Whenever I try to open a .csv file with the python command fread = open('input.csv', 'r') it always opens the file with spaces between every single character. I'm guessing it's something wrong with the text file because I can open other text files with the same command and they are loaded correctly. Does anyone know why a text file wou...

Finding anchor text when there are tags there

I want to find the text between a pair of <a> tags that link to a given site Here's the re string that I'm using to find the content: r'''(<a([^<>]*)href=("|')(http://)?(www\.)?%s([^'"]*)("|')([^&lt;&gt;]*)&gt;([^&lt;]*))&lt;/a&gt;''' % our_url The result will be something like this: r'''(<a([^<>]*)href=("|')(http://)?(www\.)?stacko...

Need python lxml syntax help for parsing html

Hello! I am brand new to python, and I need some help with the syntax for finding and iterating through html tags using lxml. Here are the use-cases I am dealing with: HTML file is fairly well formed (but not perfect). Has multiple tables on screen, one containing a set of search results, and one each for a header and footer. Each ...

Using PyQT, how do you filter mousePressEvent for a QComboBox with custom list

I've got a QComboBox with a custom list object. Please see Screen shot The custom list object has a custom mousePressEvent so that when the user click on one of the circles with a +/- (a twisty), the list is expanded/collapsed. When I use the list with the combo box, when the user clicks on a twisty, the list is expanded/collapsed, ...

What is the proper way to address permissions?

I added a new model with one permission, and now I need to add that permission to a few users on the production machine after deploying the code and running syncdb for the new app involved. I haven't found the correct way to do this. The auth docs mention User.user_permissions.add(permission), but never tell me what 'permission' is or th...

Using for...else in Python generator expressions

I'm a big fan of Python's for...else syntax - it's surprising how often it's applicable, and how effectively it can simplify code. However, I've not figured out a nice way to use it in a generator expression, for example: def iterate(i): for value in i: yield value else: print 'i is empty' In the above example...

How would you draw cell borders in a wxPython FlexGridSizer?

I'm new to Python, but I can't really find much decent documentation on the web, so I'm hoping somebody will know the answer or where the answer is... I have a wxPython FlexGridSizer bound to a panel that contains other FlexGridSizers, I'd like to display some cell borders on the main FlexGridSizer, so each section looks encapsulated bu...

Multicast in Python

How do you send and receive UDP Multicast in Python? Is there a standard library to do so? ...