python

Alternative to zc.buildout that runs on Python3

My project uses buildout to do primarily two things: automatically fetch dependencies and create scripts; and setup cron jobs (on deployment machines) using the usercrontab buildout recipe. But buildout is not yet available for Python 3. So I would like to consider alternatives for buildout. I know that both virtualenv and pip work on ...

How can I get sessions to work if I'm using Google App Engine + Django 1.1?

Is there a way for me to get sessions working? I know Django has built in session management, and GAE has some tools for it if you're using their watered down version of Django 0.96, but is there a way to get sessions to work if you're trying to use GAE w/ Django 1.1 (i.e. use_library() call). I assume using a db-backed session doesn't...

In Python, how to make sure database connection will always close before leaving a code block?

I want to prevent database connection being open as much as possible, because this code will run on an intensive used server and people here already told me database connections should always be closed as soon as possible. def do_something_that_needs_database (): dbConnection = MySQLdb.connect(host=args['database_host'], user=args['...

Dimension Reduction in Categorical Data with missing values

I have a regression model in which the dependent variable is continuous but ninety percent of the independent variables are categorical(both ordered and unordered) and around thirty percent of the records have missing values(to make matters worse they are missing randomly without any pattern, that is, more that forty five percent of the ...

huff model in gis

hello all, how would be the simplest version of the Huff model for territorial and economic analysis? sig using algorithms that I recommend or free libraries for working with files both vector and raster OGR ...

Python subprocess.Popen hangs in 'for l in p.stdout' until p terminates, why?

I have that code: #!/usr/bin/python -u localport = 9876 import sys, re, os from subprocess import * tun = Popen(["./newtunnel", "22", str(localport)], stdout=PIPE, stderr=STDOUT) print "** Started tunnel, waiting to be ready ..." for l in tun.stdout: sys.stdout.write(l) if re.search("Waiting for connection", l): ...

pysqlite2: ProgrammingError - You must not use 8-bit bytestrings

I'm currently persisting filenames in a sqlite database for my own purposes. Whenever I try to insert a file that has a special character (like é etc.), it throws the following error: pysqlite2.dbapi2.ProgrammingError: You must not use 8-bit bytestrings unless you use a text_factory that can interpret 8-bit bytestrings (like text_facto...

import problem with twisted.web server

I'm just getting started with twisted.web, and I'm having trouble importing a Python module into a .rpy script. in C:\py\twisted\mysite.py, I have this: from twisted.web.resource import Resource from twisted.web import server class MySite(Resource): def render_GET(self, request): request.write("<!DOCTYPE html>") re...

TinyMce File browser for pylons?

Hi. Did you now some ajax based filebrowser to TinyMCE wich can i use in my pylons app? Thanks, for help :) ...

get open TCP port in Python

I want to get any random open TCP port on localhost in Python. What is the easiest way? ...

increasing string size through loop

what's a simple way to increase the length of a string to an arbitrary integer x? like 'a' goes to 'z' and then goes to 'aa' to 'zz' to 'aaa', etc. ...

Python msn hook - possible?

Is it possible to hook msn via a python application to send messages to your contacts etc? ...

Cluster Graph Visualization using python

I am assembling different visualization tools that are available in python language. I found the Treemap. (http://pypi.python.org/pypi/treemap/1.05) Can you suggest some other tools that are available. I am exploring different ways of visualization of web data. ...

Why doesn't negative values for the second index in a jagged array work in Python?

For example, if I have the following (data from Project Euler): s = [[75], [95, 64], [17, 47, 82], [18, 35, 87, 10], [20, 4, 82, 47, 65], [19, 1, 23, 75, 3, 34], [88, 2, 77, 73, 7, 63, 67], [99, 65, 4, 28, 6, 16, 70, 92], [41, 41, 26, 56, 83, 40, 80, 70, 33], [41, 48, 72, 33, 47, 32, 37, 16, ...

Efficient update of SQLite table with many records

I am trying to use sqlite (sqlite3) for a project to store hundreds of thousands of records (would like sqlite so users of the program don't have to run a [my]sql server). I have to update hundreds of thousands of records sometimes to enter left right values (they are hierarchical), but have found the standard update table set left_va...

Javascript or Python? beginner getting up to speed

Which language will allow a beginner to get up to speed quicker? Basically which language of the two is easier to learn ...

How can this verbose, unpythonic routine be improved?

Is there a more pythonic way of doing this? I am trying to find the eight neighbours of an integer coordinate lying within an extent. I am interested in reducing its verbosity without sacrificing execution speed. def fringe8((px, py), (x1, y1, x2, y2)): f = [(px - 1, py - 1), (px - 1, py), (px - 1, py + 1), ...

I don't like Python functions that take two or more iterables. Is it a good idea?

This question came from looking at this question on Stackoverflow. def fringe8((px, py), (x1, y1, x2, y2)): Personally, it's been one of my pet peeves to see a function that takes two arguments with fixed-number iterables (like a tuple) or two or more dictionaries (Like in the Shotgun API). It's just hard to use, because of all the ve...

Best data-structure to use for two ended sorted list

I need a collection data-structure that can do the following: Be sorted Allow me to quickly pop values off the front and back of the list O(log n) Remain sorted after I insert a new value Allow a user-specified comparison function, as I will be storing tuples and want to sort on a particular value Thread-safety is not required Optiona...

Django aggregation query on related one-to-many objects

Here is my simplified model: class Item(models.Model): pass class TrackingPoint(models.Model): item = models.ForeignKey(Item) created = models.DateField() data = models.IntegerField() class Meta: unique_together = ('item', 'created') In many parts of my application I need to retrieve a set of Item's and a...