python

Python dlopen/dlfunc/dlsym wrappers

Anybody knows if actually exists a wrapper or ported library to access to Unix dynamic linker on Python? ...

Django Form Preview - How to work with 'cleaned_data'

Thanks to Insin for answering a previous question related to this one. His answer worked and works well, however, I'm perplexed at the provision of 'cleaned_data', or more precisely, how to use it? class RegistrationFormPreview(FormPreview): preview_template = 'workshops/workshop_register_preview.html' form_template = ...

How to run an operation on a collection in Python and collect the results?

How to run an operation on a collection in Python and collect the results? So if I have a list of 100 numbers, and I want to run a function like this for each of them: Operation ( originalElement, anotherVar ) # returns new number. and collect the result like so: result = another list... How do I do it? Maybe using lambdas? ...

Single implementation to cover both single and multiple values in Python?

Say you have a value like this: n = 5 and a method that returns the factorial of it, like so: Factorial ( 5 ) How do you handle multiple values: nums = [1,2,3,4,5] Factorial ( nums ) so it returns the factorials of all these values as a list. What's the cleanest way to handle this, without writing 2 methods? Does python have a go...

Python equivalent to java.util.SortedSet?

Does anybody know if Python has an equivalent to Java's SortedSet interface? Heres what I'm looking for: lets say I have an object of type foo, and I know how to compare two objects of type foo to see whether foo1 is "greater than" or "less than" foo2. I want a way of storing many objects of type foo in a list L, so that whenever I trav...

Decoding HTML Entities With Python

The following Python code uses BeautifulStoneSoup to fetch the LibraryThing API information for Tolkien's "The Children of Húrin". import urllib2 from BeautifulSoup import BeautifulStoneSoup URL = ("http://www.librarything.com/services/rest/1.0/" "?method=librarything.ck.getwork&id=1907912" "&apikey=2a2e596b887...

Google Data Source JSON not valid?

I am implementing a Google Data Source using their Python Library. I would like the response from the library to be able to be imported in another Python script using the simplejson library. However, even their example doesn't validate in JSONLint: {cols: [{id:'name',label:'Name',type:'string'}, {id:'salary',label:'Salary',ty...

Difference between the use of double quote and quotes in python

Is there any difference between the use of double quotes to single quotes in Python? "A string with double quotes" 'A string with single quotes' Are they identical? Are there differences in how python interprets these strings? ...

How to divide a set of overlapping ranges into non-overlapping ranges?

Let's say you have a set of ranges: 0 - 100: 'a' 0 - 75: 'b' 95 - 150: 'c' 120 - 130: 'd' Obviously, these ranges overlap at certain points. How would you dissect these ranges to produce a list of non-overlapping ranges, while retaining information associated with their original range (in this case, the letter after the range)? For ...

Performance Advantages to Iterators?

What (if any) performance advantages are offered by using iterators. It seems like the 'Right Way' to solve many problems, but does it create faster/more memory-conscious code? I'm thinking specifically in Python, but don't restrict answers to just that. ...

Privilege Escalation in Web Environment for File Access

I have a situation where I would like to elevate the permissions I have in a web environment so that I can access a serial device. The specific case is where I have a web interface for configuring a modem that comes up on /dev/ttyUSB[0-9]. Zero or more modems will be plugged in by an end user. I am writing some software that is capab...

How do I send a HTTP POST value to a (PHP) page using Python?

Hi all! I have a PHP page that has 1 textbox and when I press on the submit button. My SQL is going to store this product name into my database. My question is; is it possible to send/post the product name using Python script that asks for 1 value and then use my PHP page to send it to my database? Thanks! ...

Deploying Google Analytics With Django

We're about to deploy a new Django website, and we want to use Google Analytics to keep track of traffic on the site. However, we don't want all of the hits on development instances to contribute to the Google Analytics statistics. There are a few ways we could deal with this: have a configuration option in settings.py which the base...

Why avoid CGI for Python with LAMP hosting?

I have been using PHP for years. Lately I've come across numerous forum posts stating that PHP is outdated, that modern programming languages are easier, more secure, etc. etc. So, I decided to start learning Python. Since I'm used to using PHP, I just started building pages by uploading an .htaccess file with: addtype text/html py add...

BeautifulSoup gives me unicode+html symbols, rather than straight up unicode. Is this a bug or misunderstanding?

I'm using BeautifulSoup to scrape a website. The website's page renders fine in my browser: Oxfam International’s report entitled “Offside! http://www.coopamerica.org/programs/responsibleshopper/company.cfm?id=271 In particular, the single and double quotes look fine. They look html symbols rather than ascii, though strangely wh...

How can I use python's telnetlib to fetch data from a device for a fixed period of time?

Hi, I'm connecting to a hardware device via telnet. That device is pretty simple in terms of I/O. So I submit a command to it, and after that the device pumps out data one line at a time, once per second. Each line just contains a number. So my question is this: if I connect to this device using python's telnetlib, how can I fetch data...

Is there any reasonable SSDP or DIDL Lib for java/groovy/python?

For a future project I am looking for a library to handle SSDP communication and messages in DIDL-Lite xml dialect. Is there any reasonable implementation of java, groovy or python? I don't like to use implementations of existing UPnP stacks like cybergarage or the frauenhofer UPnP stack because they are highly depending on these stack...

Detect whether charset exists in python

Is it possible to check in Python whether a given charset exists/is installed. For example: check('iso-8859-1') -> True check('bla') -> False ...

Hello world Pyamf small error message

Hi i am trying to link flex to django with Pyamf As a first step i tried the basic Hello World http://pyamf.org/wiki/DjangoHowto But that results in an ErrorFault. I use django 1.0.2 amfgateway.py in the root folder of my project (same level as settings) import pyamf from pyamf.remoting.gateway.django import DjangoGateway from djan...

Interruptible thread join in Python

Is there any way to wait for termination of a thread, but still intercept signals? Consider the following C program: #include <signal.h> #include <stdio.h> #include <sys/types.h> #include <unistd.h> #include <pthread.h> #include <stdlib.h> void* server_thread(void* dummy) { sleep(10); printf("Served\n"); return NULL; } v...