python

Resilient '%' escape for string formatting in Python

I have a string, specifically a SQL query, that goes through multiple formatting passes before it is passed to the backend to be executed, at which point Django performs yet another string format. How can I preserve the placeholders that need to make it to the database throughout all of this? Something like the following is the best I've...

How to find the source of increasing memory usage of a twisted server?

I have an audio broadcasting server written in Python and based on Twisted. It works fine, but its memory usage is increasing when there are more users on server, but the memory usage never goes down when those users get off line. As you see in following figure: You can see the curve of memory usage goes up where the curve of listener...

django error. about django.forms

from django import forms class a(forms.Form): name = forms.CharField(initial='Your name') url = forms.URLField(initial='Your Web site') comment = forms.CharField() data = {'name': 'hahaha', 'url': '', 'comment': 'Foo'} f = a(data,auto_id=False) #print f.is_valid() print f.errors errors: Traceback (most recent call last)...

Python sockets, how to escape from infinite loop and handle exceptions

Hi I have a script that connects to a remote server. The code is below s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((remote_host,remote_port)) s.setblocking(False) while True: try: data = s.recv(1024) if not data: break pkt_type = ord(data[2]) # get pkt type if pkt_...

Python List not getting in rendered in javascript

Hi, I have a javascript which takes two variables i.e two lists one is a list of numbers and the other list of strings from django/python numbersvar = [0,1,2,3] stringsvar = ['a','b','c'] The numbersvar is rendered perfectly but when I do {{stringsvar}} it does not render it. ...

Django: Check on type of relation a form has

I have a situation where I need to check if a form has m2m relation before saving it in views.py as I am using the same views.py for different models. Example: #models.py class BaseClass(models.Model): # Some generic stuff. class SomeClass(BaseClass): # This class doesnt have any many2many relations class SomeOtherClass(BaseCla...

sort csv by column

Hi! I want to sort a CSV table by date. Started out being a simple task: import sys import csv reader = csv.reader(open("files.csv"), delimiter=";") for id, path, title, date, author, platform, type, port in reader: print date I used Python's CSV module to read in a file with that structure: id;file;description;date;author;pla...

How to make os.mkfifo and subprocess.Popen work together?

I'm trying to redirect a patch command output using a named pipe. I tried like this: fifo = os.path.join(self.path, 'pipe') os.mkfifo(fifo) op = os.popen('cat '+ fifo) proc = Popen(['patch', current_keyframe, '--input='+fpath, '--output='+fifo], stdin=PIPE, stdout=PIPE) os.unlink(fifo) print op.read() But my script stops at Popen() ca...

Can I get the kerning value of two characters using PIL?

Is it possible to get the kerning value of two characters in a font using PIL? ...

Subtract dict A from dict B (deep del)?

If I have a deeply nested dict is there a built-in way to subtract/remove list of "paths" (eg: keyA.keyB.key1, keyA.keyC.key2, etc) or a the keys of a second dict from the original dict? Or maybe there is a common module which has functionality like this? ...

Can not get the Auth Token for GData After Authentication on App Engine

I would like to pull the Auth Token for the Gdata auth so that I can write to a google calendar. I am having issues getting the token after authentication so that I can send the token to the calendar service. I am using the default login screen provided by appengine (/_ah/login) and I am able to login and authenticate, however, I am una...

Javascript equivalent of Python's sequence unpack: a,b=(1,2) ?

Hi, is there a javascript equivalent to unpack sequences like in python (a,b=(1,2))? Thanks in advance. ...

How to call a function and change a variable

Hello, I am calling a function several times as I am testing several responses. I am asking on how I call a function earlier in the program, changing a variable in this function and then calling it. Below is a snippet of the code. class AbsoluteMove(unittest.TestCase): def Ssh(self): p=pexpect.spawn('ssh [email protected]...

Making a web interface to a script that takes 30 minutes to execute

I wrote a python script to process some data from CSV files. The script takes between 3 to 30 minutes to complete, depending on the size of the CSV. Now I want to put in a web interface to this, so I can upload the CSV data files from anywhere. I wrote a basic HTTP POST upload page and used Python's CGI module - but the script just time...

problem in installing django

problem with installing django i am geting folllowing error E:\Softwares\Django-1.1.1.tar\Django-1.1.1\Django-1.1.1>setup.py install Traceback (most recent call last): File "E:\Softwares\Django-1.1.1.tar\Django-1.1.1\Django-1.1.1\setup.py", line 48, in ? root_dir = os.path.dirname(__file__) NameError: name '__file__' is not define...

Parsing a stdout in Python

In Python I need to get the version of an external binary I need to call in my script. Let's say that I want to use Wget in Python and I want to know its version. I will call os.system( "wget --version | grep Wget" ) and then I will parse the outputted string. How to redirect the stdout of the os.command in a string in Python? ...

Google App Engine and OpenID

I am trying to implement OpenID in a GoogleAppEngine project. In this case, which OpenIDStore I have to use. Thanks ...

What is the name for [x for x in some_list] type of construct in python?

Couldn't really find it, but probably it's me not knowing how to search properly :( Just wanted to find out what the name is for: [x for x in some_list] type of construct? ...

Django primary key

When querying in djangop say People.objects.all(pk=code) Pk=code .Wht does it mean...... Thanks........ ...

serializing python objects to XML

I need to serialize my python objects to XML. I tried to use Django one but it's only for QuerySet objects and not for any simple Python object. Is there any package to do that? ...