python

Is there a reStructuredText markup editor for eclipse

Is there a WiKiText editor plugin for reStructuredText under eclipse? When I edit a .textile file, I get various intelligent editing features (such as line folding) and a preview panel. I find that there are references to reStructuredText under various MyLyn packages, but after installing them I still can't find a reStructuredText editor...

rewrite small piece of python code

I have lots of small pieces of code that look like: for it in <iterable>: if <condition>: return True/False Is there a way I can rewrite this piece of code with a lambda expression ? I know I can factor it out in a small method/function, but I am looking for some lambda thing if it can be done. ...

Is there any generic binary protocol codec library for python?

There is nice one for java - MINA. Once I've heard that there is something similar for python. But can't remind. EDIT: to be more specific, I would like to have a tool which would help me to create a coded for some binary stream. EDIT2: I'd like to list solutions here (thanks Scott for related topics) Listed in order i'd use it. bit...

Python yield returns characters instead of string from single-element tuple

I'm using yield to process each element of a list. However, if the tuple only has a single string element, yield returns the characters of the string, instead of the whole string: self.commands = ("command1") ... for command in self.commands: yield command # returns 'c' not 'command1' how can i fix this? Thanks ...

Country-based Super User Access, and modifiying Django Auth

I'm looking to give super user access to users of a program I'm devving. All the entities have a country id value, so i'm just lookign to hook up my user model to have a country ID Looking at Django Auth, It should be nice and easy to add a super_user_country_id field. However, how frowned upon is it to modify the core django classes?...

Python (1..n) syntax?

I see in the code on this Sage wiki page the following code: @interact def _(order=(1..12)): Is this (1..n) syntax unique to Sage or is it something in Python? Also, what does it do? ...

using xlrd to read Excel xls file containing Chinese and/or Hindi characters

http://scienceoss.com/read-excel-files-from-python/comment-page-1/#comment-1051 From the above link i use this utility to read an xls file.If the xls contains different language characters like chine or hindi.It does not output the exact wordings.Is there a work around for this.. After googling i found this import xlrd def upload_xls...

deploying python qt project

can you tell me how do i deploy my project on qt designer. i am using windows and also how do i convert the .py files to standard .exe ...

Auto-adjusting size for Tkinter frame.

Hello, I'm working on a gui and I'd like to know how to adjust the size of the menus of a frame in order to have them take all the horizontal space of the frame. The problem has changed : now the menu buttons are ok when the window is in normal size but when I resize it the menu buttons drop in the middle of the window. How can I make...

Looking for strong/explicit-typed language without GIL

Are there any languages which feature static type checking like in C++ with modern syntax like in Python, and does not have GIL? I belive, Python 3 with ability to explicitly declare type of each variable would be 'almost there', but GIL makes me sad. Java is nice, but I need something more 'embedable' without bulky JRE. Update: Anyth...

Filter results for Django paginator in template

I'm filtering out results from my page_obj in a generic view to only show entries published in the same language as the languge currently set by django-cms (http://www.django-cms.org/en/documentation/2.0/i18n/). This works fine, but adding in support for Django pagination (http://docs.djangoproject.com/en/1.2/topics/pagination/) causes ...

how to decode HTTP request headers and body in Python 3?

i am writing an experimental asynchronous web server. i am wondering about the standard / 'best' way to decode HTTP requests in python? basically what reading from the socket gives me is a bytes representation of the incoming request raw data; how can i turn these into standard datatypes like dictionaries, lists of values, and so on? i...

How to mount/unmount flash disk with using hal,dbus in python?

hi, i need to mount and unmount flash drive in my code -written with python- without using command line or os module. how can i mount/unmount flash drive with using dbus ( also hal)? ...

Does this PyList_Append(list, Py_BuildValue(...)) leak?

Does this leak?: static PyObject* foo(PyObject* self, PyObject* args){ PyObect* list = PyList_New(0); for(int i = 0; i < 100; i++) // leak? does PyList_Append increment ref of the temporary? PyList_Append(list, Py_BuildValue("i", 42)); return list; } Though, I suppose it's better to do this, in any case?: ...

Eclipse pydev bugs?

I don't know if you guys are having the same problem, but when I'm trying to use """ and """ for multi-lines comments in eclipse pydev, it sometimes does not work. Anybody can suggest me some better IDE? Sorry. I will try to make this clearer. It happens every time when I try to comment off looong multi lines like 300 or so. Just type w...

Cairo context and persistence?

Hi, I am just getting started using pycairo, and I ran into the following interesting error. The program I write creates a simple gtk window, draws a rectangle on it, and then has a callback to draw a random line on any kind of keyboard input. However, it seems that with each keyboard input, I have to create a new context, or I get an er...

Python: make eval safe

I want an easy way to do a "calculator api" in python. Right now I don't care much about the exact set of features the calculator is going to support. I want it to receive a string, say "1+1" and return a string with the result, in our case "2". Is there a way to make eval safe for such a thing? For a start I would do env = {} env...

Iterate across arbitrary dimension in numpy

I have a multidimensional numpy array, and I need to iterate across a given dimension. Problem is, I won't know which dimension until runtime. In other words, given an array m, I could want m[:,:,:,i] for i in xrange(n) or I could want m[:,:,i,:] for i in xrange(n) etc. I imagine that there must be a straightforward feature in num...

How to get read-only objects from database?

Hello, I'd like to query the database and get read-only objects with session object. I need to save the objects in my server and use them through the user session. If I use a object outside of the function that calls the database, I get this error: "DetachedInstanceError: Parent instance is not bound to a Session; lazy load operation o...

webpy: How to serve JSON

Is it possible to use webpy to serve JSON? I built my website and I need to serve some information in JSON to interact with the Javascript on some pages. I try to look for answers in the documentation, but I'm not able to find anything. Thanks, Giovanni ...