python

Disco/MapReduce: Using results of previous iteration as input to new iteration

Currently am implementing PageRank on Disco. As an iterative algorithm, the results of one iteration are used as input to the next iteration. I have a large file which represents all the links, with each row representing a page and the values in the row representing the pages to which it links. For Disco, I break this file into N chun...

find nearest value in numpy array

Hi, is there a numpy-thonic way, e.g. function, to find the 'nearest value' in an array? example: np.find_nearest( array, value ) thanks in advance! ...

How to make a simple cross-platform webbrowser with Python?

The http://code.google.com/p/pywebkitgtk/ looks great but it seems to be running on linux only. Does anybody know if there is something similar but cross-platform? If not what can be the alternatives to make with Python a simple web-browser that can run on Windows, MAC os and linux? Thanks in advance Update: Does anybody has some in...

easiest way to setup XEmacs on Gentoo for Python

Hi, I want to use (X)Emacs on my Gentoo system and wonder about the "correct" (or easiest) way to setup it to be used for Python development (i.e. intelligent auto-completion via tab and all those usual stuff). I want to avoid installing anything by hand - I want to use my Portage/emerge as far as possible. I have installed xemacs, py...

In Python, how to make data members visible to subclasses if not known when initializing an object ?

The title is a bit long, but it should be pretty straightforward for someone well-aware of python. I'm a python newbie. So, maybe i'm doing things in the wrong way. Suppose I have a class TreeNode class TreeNode(Node): def __init__(self, name, id): Node.__init__(self, name, id) self.children = [] and a subclass ...

Django logging features?

I need to run a lot of Django management commands in the crontab and want to log the output of each run to a special timestamped file. Is there a Django or Python module to help me do this or do I just have to roll my own? ...

Python class structure ... prep() method?

We have a metaclass, a class, and a child class for an alert system: class AlertMeta(type): """ Metaclass for all alerts Reads attrs and organizes AlertMessageType data """ def __new__(cls, base, name, attrs): new_class = super(AlertMeta, cls).__new__(cls, base, name, attrs) # do stuff to new_class return new_class clas...

Calculating Nearest Match to Mean/Stddev Pair With LibSVM

I'm new to SVMs, and I'm trying to use the Python interface to libsvm to classify a sample containing a mean and stddev. However, I'm getting nonsensical results. Is this task inappropriate for SVMs or is there an error in my use of libsvm? Below is the simple Python script I'm using to test: #!/usr/bin/env python # Simple classifier t...

Decorator for determining HTTP response from a view

I want to create a decorator that will allow me to return a raw or "string" representation of a view if a GET parameter "raw" equals "1". The concept works, but I'm stuck on how to pass context to my renderer. Here's what I have so far: from django.shortcuts import render_to_response from django.http import HttpResponse from django.te...

Disco/MapReduce: Using chain_reader on split data

My algorithm currently uses nr_reduces 1 because I need to ensure that the data for a given key is aggregated. To pass input to the next iteration, one should use "chain_reader". However, the results from a mapper are as a single result list, and it appears this means that the next map iteration takes place as a single mapper! Is ther...

Using pam_python in a script running with mod_python

Hi ! I would like to develop a web interface to allow users of a Linux system to do certain tasks related to their account. I decided to write the backend of the site using Python and mod_python on Apache. To authenticate the users, I thought I could use python_pam to query the PAM service. I adapted the example bundled with the module ...

Browser simulation - Python

Hi folks, I need to access a few HTML pages through a Python script, problem is that I need COOKIE functionality, therefore a simple urllib HTTP request won't work. Any ideas? ...

SECURITY Flaws in this design for User authentication.

SECURITY Flaws in this design for User authentication. From: http://wiki.pylonshq.com/display/pylonscookbook/Simple+Homegrown+Authentication Note: a. Project follows the MVC pattern. b. Only a user with a valid username and password is allowed submit something. Design: a. Have a base controller from which all controllers ...

Eclipse: PyDev installation difficulties

I'm having difficulty getting PyDev to work. I had an installation of Eclipse for PHP developers (1.2.1.20090918-0703). A month ago, I installed PyDev, and everything worked great. I go to fire it up this morning, and PyDev is gone. There is no option to create a Python project, the Python language editor is missing, etc. Eclipse for ...

Python HTTPSConnection.close() does not appear to close the connection?

I'm not sure if this is a bug or if I'm just doing something wrong. If I were to do an HTTP connection like this: import httplib http_connection = httplib.HTTPConnection("192.168.192.196") http_connection.request("GET", "/") http_connection.sock.settimeout(20) response = http_connection.getresponse() data = response.read() http_connec...

An extended Bezier Library or Algorithms of bezier operations

Hi, Is there a library of data structures and operations for quadratic bezier curves? I need to implement: bezier to bitmap converting with arbitrary quality optimizing bezier curves common operations like subtraction, extraction, rendering etc. languages: c,c++,.net,python Algorithms without implementation (pseudocode or etc) could ...

Avoiding thumbnail name collisions with sorl-thumbnail

Understanding that I should probably just dig into the source to come up with a solution, I'm wondering if anyone has come up with a tactic for dealing with this. In my project, I have a lot of images being generated outside of the application. I'm isolating them on the filesystem based on a model's pk. For example, a model instance w...

Can I use HTTP Post Requests for SOAP? - SOAP and Django

Hi folks, I am wondering if I could use simply use HTTP POST Requests in order to implement a SOAP API. If so how should I format and treat the requests? ...

Python -- what is NOT in 2.7 that IS in 3.1? So many things have been back-ported, what is NOT?

I've been following the saga of Python 3.x and have watched the 3.x features gradually getting back-ported to the 2.x line. Most of the libraries I use haven't been ported and some (e.g. Twisted) seem covertly or overtly hostile to 3.x to varying degrees. At any rate, there has been very little movement towards compatible versions of...

Nested generator functions in python

Consider a tuple v = (a,b,c) and a generator function generate(x) which receives an item from the tuple and generates several options for each item. What is the pythonic way of generating a set of all the possible combinations of the result of generate(x) on each item in the tuple? I could do this: v = (a,b,c) for d in generate(v[0]):...