python

Sorted collections: How do i get (extended) slices right?

How can I resolve this? >>> class unslice: ... def __getitem__(self, item): print type(item), ":", item ... >>> u = unslice() >>> u[1,2] # using an extended slice <type 'tuple'> : (1, 2) >>> t = (1, 2) >>> u[t] # or passing a plain tuple <type 'tuple'> : (1, 2) Rational: I'm currently overengineering a sorted associative col...

drawing a pixbuf onto a drawing area using pygtk and glade.

Hi, i'm trying to make a GTK application in python where I can just draw a loaded image onto the screen where I click on it. The way I am trying to do this is by loading the image into a pixbuf file, and then drawing that pixbuf onto a drawing area. the main line of code is here: def drawing_refresh(self, widget, event): #clear the...

Python bindings for libparted?

I'm looking for a way to interact with the GNU libparted library from Python, but so far what I've found, a GSOC project from 2005 and an Ubuntu/debian package that's been dropped from the archive, have been disheartening. Is there something I'm missing, or should I just get used to manipulating libparted from the command line / trying...

Filetype information

I'm in the process of writing a python script, and I want to find out information about a file, such as for example a mime-type (or any useful depiction of what a file contains). I've heard about python-magic, but I'm really looking for the solution that will allow me to find this information, without requiring the installation of addit...

access eggs in python?

Hello Again I need your wisdom and insight. Is it any way to call an installed python egg from a python code? I need to cal a sphinx documentation generator from within a python code, and currently i'm doing it like this: os.system( "sphinx-build.exe -b html c:\src c:\dst" ) This works, but requires some additional configuration: 'scr...

What is "generator object" in django?

Am using Django voting package and when i use the method get_top() in the shell, it returns something like "generator object at 0x022f7AD0, i've never seen anything like this before, how do you access it and what is it? my code: v=Vote.objects.get_top(myModel, limit=10, reversed=False) print v <generator object at 0x022f7AD0> NB: I t...

How to get the public channel URL from YouTubeVideoFeed object using the YouTube API?

I'm using the Python version of the YouTube API to get a YouTubeVideoFeed object using the following URL: http://gdata.youtube.com/feeds/api/users/USERNAME/uploads Note: I've replaced USERNAME with the account I need to follow. So far getting the feed, iterating the entries, getting player urls, titles and thumbnails has all been ...

Multiple simultaneous network connections - Telnet server, Python.

I'm currently writing a telnet server in Python. It's a content server. People would connect to the server via telnet, and be presented with text-only content. My problem is that the server would obviously need to support more than one simultaneous connection. The current implementation I have now supports only one. This is the basic,...

Appengine - Possible to get an entity using only key string without model name?

I want to be able to have a view that will act upon a number of different types of objects all the view will get is the key string eg: agpwb2xsdGhyZWFkchULEg9wb2xsY29yZV9hbnN3ZXIYAww without knowing the model type, is it possible to retrieve the entity from just that key string? thanks ...

Qt-style documentation using Doxygen?

How do I produce Qt-style documentation (Trolltech's C++ Qt or Riverbank's PyQt docs) with Doxygen? I am documenting Python, and I would like to be able to improve the default function brief that it produces. In particular, I would like to be able to see the return type (which can be user specified) and the parameters in the function br...

Simple webserver or web testing framework

Need to testcase a complex webapp which does some interacting with a remote 3rd party cgi based webservices. Iam planing to implement some of the 3rd party services in a dummy webserver, so that i have full controll about the testcases. Looking for a simple python http webserver or framework to emulate the 3rd party interface. ...

Using Twisted's twisted.web classes, how do I flush my outgoing buffers?

I've made a simple http server using Twisted, which sends the Content-Type: multipart/x-mixed-replace header. I'm using this to test an http client which I want to set up to accept a long-term stream. The problem that has arisen is that my client request hangs until the http.Request calls self.finish(), then it receives all multipart do...

fastest way to store comment data python

Hi I have a small comment shoutbox type cgi process running on a server and currently when someone leaves a comment I simply format that comment into html i.e <p class="title">$title</p> <p class="comment">$comment</p> and store in a flat file. Would it be faster and acceptably low in LOC to reimplement the storage in xml or json, in a...

Python reflection - Can I use this to get the source code of a method definition.

Duplicate of.. How can I get the code of python function? print the code which defined a lambda function Python: How do you get Python to write down the code of a function it has in memory? I have a method definition which is successfully running, but would like to modify it in runtime. for eg: If i have a method def sayHello(): ...

Django Form values without HTML escape.

Hi, I need to set the Django forms.ChoiceField to display the currency symbols. Since django forms escape all the HTML ASCII characters, I can't get the &#36; ( ) or the &pound; ( ) to display the currency symbol. <select id="id_currency" name="currency"> <option value="&amp;#36;">&#36;</option> <option value="&amp;pound;">&...

Efficient arbitrary-sized integer packing in Python

The struct.pack() function allows converting integers of up to 64 bit to byte strings. What's the most efficient way to pack an even larger integer? I'd rather not add a dependency on non-standard modules like PyCrypto (which provides num_to_bytes()). ...

How do I set up a model to use an AutoField with a legacy database in Python?

I have a legacy database with an integer set as a primary key. It was initially managed manually, but since we are wanting to move to django, the admin tool seemed to be the right place to start. I created the model and am trying to set the primary key to be an autofield. It doesn't seem to be remembering the old id in updates, and it do...

Other than basic python syntax, what other key areas should I learn to get a website live?

Other than basic python syntax, what other key areas should I learn to get a website live? Is there a web.config in the python world? Which libraries handle things like authentication? or is that all done manually via session cookies and database tables? Are there any web specific libraries? Edit: sorry! I am well versed in asp.net,...

Python subprocess "object has no attribute 'fileno'" error

This code generates "AttributeError: 'Popen' object has no attribute 'fileno'" when run with Python 2.5.1 Code: def get_blame(filename): proc = [] proc.append(Popen(['svn', 'blame', shellquote(filename)], stdout=PIPE)) proc.append(Popen(['tr', '-s', r"'\040'"], stdin=proc[-1]), stdout=PIPE) proc.append(Popen(['tr', r"...

How to query any constraint's target list without knowing the constraint type?

In Maya, I have a list of constraints gathered by the following code. I want to iterate the constraints and query the targets for each of them: cons = ls(type='constraint') for con in cons: targets = constraint(query=True, targetList=True) The problem, there is no general constraint command for manipulating all constraints. Inste...