python

virtualenv yolk problem

yolk -l gives me information that I've got 114 packages installed on my Ubuntu 10.04. After creating new virtualenv directory using virtualenv virt_env/virt1 --no-site-packages --clear I switched to that, my prompt changed and then yolk -l gives me again the same 114 packages. What is going on there? ...

removing non ascii characters from a string using python / django

I have a string of HTML stored in a database. Unfortunately it contains characters such as ® I want to replace these characters by their HTML equivalent, either in the DB itself or using a Find Replace in my Python / Django code. Any suggestions on how I can do this? ...

Performing non-blocking requests? - Django

Hi folks, I have been playing with other frameworks, such as NodeJS, lately. I love the possibility to return a response, and still being able to do further operations. e.g. def view(request): do_something() return HttpResponse() do_more_stuff() #not possible!!! Maybe Django already offers a way to perform operations afte...

How to change User-Agent on Google App Engine UrlFetch service?

Is it possible to change User-Agent of Google App Engine UrlFetch service? ...

Installing OSQA on windows(Local system)

Hi I want to install osqa on windows local system for this i have downloaded bitnami-djangostack-1.1.1-2-windows-installer.exe which has in built django,python,mysql & apache. I have run a django example given on the django website. Its working fine. But i am confused how to install osqa. I have downloaded the source code available on...

Python IDLE freezes

This is absolutely frustrating, but I am not sure if the following is an issue only on my machine or with IDLE in general. When attempting to print a long list in the shell, and that could happen by accident while debugging, the program crushes and you have to restart it manually. Even worse, if you have a few editor windows open, it a...

Programatically check whether a drive letter is a shared/network drive

Hi SO community! I searched a while but found nothing that helped me. Is there a way to check whether a drive letter stands for a shared drive/network drive or a local disc in python? I guess there is some windows api function that gives me that info, but I cant find it. Perhaps there is even a method already integrated in python? What...

Sorting objects in Python

I want to sort objects using by one of their attributes. As of now, I am doing it in the following way USpeople.sort(key=lambda person: person.utility[chosenCar],reverse=True) This works fine, but I have read that using operator.attrgetter() might be a faster way to achieve this sort. First, is this correct? Assuming that it is correc...

Best deployment strategy for Python google app engine

I wonder if there are any best practices/patterns for deploying python apps on Google app engine specifically Django. The best practice should be combination of existing best practices viz. Fabric, Paver, Buildout etc. Also please share best practice patterns for developing (I could not get virtualenv running with Django and Django App e...

Defining ways to visualise admin fields - Django

Hi folks, I'm trying to add graphs to the admin interface, problem is that I have not found any documentation regarding this. I'm sure there are generally accepted ways of customizing the way fields are displayed, and I do not wish to follow any problematic route. Any ideas? Edit: this is a model I'm trying to reproduce! Un...

python iterators and thread-safety

I have a class which is being operated on by two functions. One function creates a list of widgets and writes it into the class: def updateWidgets(self): widgets = self.generateWidgetList() self.widgets = widgets the other function deals with the widgets in some way: def workOnWidgets(self): for widget in self.widgets: ...

setting the header of a response in python / django

This is my code: template = loader.get_template('blog/post.html') c = Context(parameterDict) return HttpResponse(template.render(c)) I am using this to render data into a template(contained in parameterDict). The problem is that parameterDict contains certain UTF characters like ®. This is causing a problem in my template...

How do I use python-webkit2png to take many screenshots at the same time?

I've got thousands of urls from many hosts I need to screenshot. I can use the lib fine from the command line, but how can I integrate it into my code so I can take multiple screenshots simultaneously? I think it's something to do with xvfb as with the answer to this question: http://stackoverflow.com/questions/1747022/how-to-kill-hea...

Python: Plot some data (matplotlib) without GIL

Hello all, my problem is the GIL of course. While I'm analysing data it would be nice to present some plots in between (so it's not too boring waiting for results) But the GIL prevents this (and this is bringing me to the point of asking myself if Python was such a good idea in the first place). I can only display the plot, wait till ...

Change text_factory in Django/sqlite

I have a django project that uses a sqlite database that can be written to by an external tool. The text is supposed to be UTF-8, but in some cases there will be errors in the encoding. The text is from an external source, so I cannot control the encoding. Yes, I know that I could write a "wrapping layer" between the external source and ...

python: subclass a metaclass

Hello, for putting methods of various classes into a global registry I'm using a decorator with a metaclass. The decorator tags, the metaclass puts the function in the registry: class ExposedMethod (object): def __init__(self, decoratedFunction): self._decoratedFunction = decoratedFunction def __call__(__self,*__args,*...

Capture global touch events (Symbian)

Basically I wanted what the pys60 module keycapture does (global capture of keystrokes) but I wanted to do this with the touchscreen. So if the program is running, all touch events can be intercepted and logged by the program. How is this possible? ...

Background color for Tk in Python

I'm writing a slideshow program with Tkinter, but I don't know how to change the background color to black instead of the standard light gray. How can this be done? import os, sys import Tkinter import Image, ImageTk import time root = Tkinter.Tk() w, h = root.winfo_screenwidth(), root.winfo_screenheight() root.overrideredirect(1) root...

Basic Python: Exception raising and local variable scope / binding

I have a basic "best practices" Python question. I see that there are already StackOverflow answers tangentially related to this question but they're mired in complicated examples or involve multiple factors. Given this code: #!/usr/bin/python def test_function(): try: a = str(5) raise b = str(6) except: ...

differences between "d = dict()" and "d = {}"

Why would one use one over the other: d = dict() ~0.208 usec d = {} ~0.06 usec ...