python

how to get feedparser to send a cache-control header?

I'm using python feedparser in an aggregator client that runs behind a squid proxy. I want it to send a cache-control: max-age=600 header in the request, so that we get a reasonably up-to-date response. (At the moment the feeds are returned by the proxy from its cache, even days after they changed, which is reasonable based on heuristi...

Python matplotlib: memory not being released when specifying figure size

I'm using matplotlib to generate many plots of the results of a numerical simulation. The plots are used as frames in a video, and so I'm generating many of them by repeatedly calling a function similar to this one: from pylab import * def plot_density(filename,i,t,psi_Na): figure(figsize=(8,6)) imshow(abs(psi_Na)**2,origin =...

Python: Check the value of a variable passed as a parameter in another method?

Somewhat related to my earlier question. I'm making a simple html parser to play around with in Python 2.7. I would like to have multiple parse types, IE can parse for links, script tags, images, ect. I'm using the HTMLParser module, so my initial thoughts were just make a separate class for each thing I want to parse. But that seemed ra...

How to redirect to a url with non-English characters?

I'm using pylons, and some of my urls contains non-English characters, such as: http://localhost:5000/article/111/文章标题 At most cases, it won't be a problem, but in my login module, after a user has logging out, I try to get the referer from the request.headers, and redirect to that url. if user_logout: referer = request.headers.g...

Encoding problem in app engine when submitting multipart/form-data forms.

I have a simple form that submits a image to the blobstore and a title for the image. This works on my local devserver but when I deploy my code, non ascii letters in the title become garbled with some kind of mixture of ascii and hex. For example Ísland becomes =CDsland. Note, I am using <meta http-equiv="Content-Type" content="text/...

Python: How to custom order a list?

Obs: I know lists in python are not order-fixed, but think that this one will be. And I'm using Python 2.4 I have a list, like (for example) this one: mylist = [ ( u'Article', {"...some_data..."} ) , ( u'Report' , {"...some_data..."} ) , ( u'Book' , {"...another_data..."} ) , ...#continue ] This variable...

svcrack.py and svwar.py

hello, i found out that my server is getting slower and slower. on command top i get response that i have a lot svcrack.py and svwar.py processes active. can you tell me what are those? thank you in advance! ...

RPC frameworks available?

I am looking to use a RPC framework for internal use. The framework has to be cross language. I am exploring Apache Thrift right now. Google protocol Buffers does not provide RPC capabilities exactly. What are the choices I have got apart from Thrift. (my servers will be primarily Java and the clients will be Java, Python, PHP). ...

How to provide additional initialization for a subclass of namedtuple?

Suppose I have a namedtuple like this: EdgeBase = namedtuple("EdgeBase", "left, right") I want to implement a custom hash-function for this, so I create the following subclass: class Edge(EdgeBase): def __hash__(self): return hash(self.left) * hash(self.right) Since the object is immutable, I want the hash-value to be c...

Problems installing lxml on a Mac, it installs but module not found

The code from lxml import etree produces the error ImportError: No module named lxml Running sudo easy_install lxml results in lxml 2.2.7 is already the active version in easy-install.pth Removing lxml-2.2.7-py2.5-macosx-10.3-i386.egg from site-packages and rerunning sudo easy_install lxml results in Adding lxml 2.2.7 to ea...

trying to get vim to work with python

Im trying to get code completion for python in vim 7.3. When I install vim I use this configuration: ./configure --prefix=${HOME}/vim73 --enable-python3interp=yes --with-python3-config-dir=/home/etobkru/Python3/lib/python3.1/config make && make install I copy this file: http://vim.cybermirror.org/runtime/autoload/python3complete.vim ...

How do I use Python socket ports and make sure that windows won't block them (like ipmsg.exe for example)? (involving maya)

Hi, I am trying to create a Maya to Maya interface using Python so I could possibly make a game from within Maya that runs on two different computer. I have successfully written ways to send commands from one Maya to another using the command "commandPort." The problem is when I start sending commands from another computer, it fails.I g...

Django QuerySet Custom Ordering by ID

Given a list of ids/pks, I'd like to generate a QuerySet of objects ordered by the index in the list. Normally I'd begin with: pk_list = [5, 9, 2, 14] queryset = MyModel.objects.filter(pk__in=pk_list) This of course returns the objects, but in the order of the models meta ordering property, and I wish to get the records in the order ...

Python error "NameError: global name 'self' is not defined" when calling another method in same class

Hello all. I get a weird error: Traceback (most recent call last): File "/remote/us01home15/ldagan/python/add_parallel_definition.py", line 36, in <module> new_netlist.lines=orig_netlist.add_parallel_extention(cell_name,parallel,int(level)) File "/remote/us01home15/ldagan/python/hspice_netlist.py", line 70, in add_parallel_extention new...

Parsing document with python minidom

I have the following XML document that I have to parse using python's minidom: <?xml version="1.0" encoding="UTF-8"?> <root> <bash-function activated="True"> <name>lsal</name> <description>List directory content (-al)</description> <code>ls -al</code> </bash-function> <bash-function activated="True"...

how to increase the number of pages comes in google search?

I am using google search api But by default it shows 4 and maximum 8 results per page. I want more results per page. ...

Django and PIL on Snow Leopard

I am trying to get PIL working with Django 1.2.1 and Python 2.7 on Snow Leopard I have followed instructions I found here on SO and I should be doing it right. The imports and selftest.py works fine and I both save and open images in the interactive python, but Django cannot use it. I get the error The _imaging C module is not instal...

What is the IPv6 alternative to socket.getfqdn in Python?

socket.getfqdn() works fine with IPv4 addresses, for example: >>> import socket >>> socket.getfqdn("8.8.8.8") 'google-public-dns-a.google.com' However, it doesn't work for IPv6 addresses. >>> socket.getfqdn("2404:6800:8004::68") '2404:6800:8004::68' >>> socket.has_ipv6 True How can I do this with IPv6? Ideally with only modules in...

Dealing with metaclass conflict with SQL Alchemy declarative base

I have a class X which derives from a class with its own metaclass Meta. I want to also derive X from the declarative base in SQL Alchemy. But I can't do the simple def class MyBase(metaclass = Meta): #... def class X(declarative_base(), MyBase): #... since I would get metaclass conflict error: 'the metaclass of a derived cl...

SQL-like JOIN on two text files in Python, is there a built-in way?

A common task I have to perform is an SQL-like JOIN on two text files. i.e. create a new file from the "left hand" and "right hand" files, using some sort of join on an identifier column shared between them. Variations such as outer joins etc are sometimes required. Of course I could write a simple script to do this in a generic way, b...