python

ORM library for automatically mapping foreign keys in Python or Ruby

A frequent task I run into at work is writing scripts against pre-existing databases. Sometimes I'm connecting to Oracle, other times it might be MySql or even sql server. What I would like is a tool which would reverse-engineer the database's tables and foreign keys and allow me to write OO-style scripts against the database. This coul...

validating correct answer with loops in python

Sorry for the non descriptive question I had no idea how to word it. I'm trying to write a program (GUI) where I ask the users questions and then in return they answer and see if they are correct however when I enter the correct answer it's still showing as being incorrect. My code looks something like this. prompt for question 1 txt...

"unpacking" a passed dictionary into the function's name space in Python?

In the work I do, I often have parameters that I need to group into subsets for convenience: d1 = {'x':1,'y':2} d2 = {'a':3,'b':4} I do this by passing in multiple dictionaries. Most of the time I use the passed dictionary directly, i.e.: def f(d1,d2): for k in d1: blah( d1[k] ) In some functions I need to access the v...

Executing server-side Unix scripts asynchronously

We have a collection of Unix scripts (and/or Python modules) that each perform a long running task. I would like to provide a web interface for them that does the following: Asks for relevant data to pass into scripts. Allows for starting/stopping/killing them. Allows for monitoring the progress and/or other information provided by the...

Test if point is in some rectangle

I have a large collection of rectangles, all of the same size. I am generating random points that should not fall in these rectangles, so what I wish to do is test if the generated point lies in one of the rectangles, and if it does, generate a new point. Using R-trees seem to work, but they are really meant for rectangles and not point...

Does anyone know of a asynchronous mysql lib for python?

I've been looking into non-blocking servers for python (tornado, twisted etc) but a lot of the benefits seems to be lost if there's no non-blocking connection to the database. Does anyone know if there are any projects that take care of this? (by non-blocking a la node.js) Edit: Clarified my question ...

How do you you run a Twisted application via Python (instead of via Twisted)?

I am working my way through learning Twisted, and have stumbled across something I'm not sure I'm terribly fond of - the "Twisted Command Prompt". I am fiddling around with Twisted on my Windows machine, and tried running the "Chat" example: from twisted.protocols import basic class MyChat(basic.LineReceiver): def connectionMade(s...

How do I check the methods that an object has, in Python?

For example, a list. l1 = [1, 5 , 7] How do I check the methods that it has? (l1.append, for example) Or a string... string.lower( ...

paster errors after installing distribute 0.6.10

Been working on a Plone site for the last few weeks, it's the first time I've worked on one using buildout for recipes and paster for template generation, and it's been a learning curve. two days ago, everything was working fine. Yesterday, I started working from my known good source and used paster to generate boilerplate for a new...

python csv into dictionary

I am pretty new to python. I need to create a class that loads csv data into a dictionary. I want to be able to control the keys and value So let say the following code, I can pull out worker1.name or worker1.age anytime i want. class ageName(object): '''class to represent a person''' def __init__(self, name, age): self.name = name sel...

What is the difference between the __int__ and __index__ methods in Python 3?

The Data Model section of the Python 3.1 documentation provides the following descriptions for the __int__ and __index__ methods: object.__int__(self) Called to implement the built-in [function int()]. Should return a value of the appropriate type. object.__index__(self) Called to implement operator.index(). Also calle...

Twisted ignoring data sent from MUD Clients?

I have the following code (almost an exact copy of the Chat server example listed here: import twisted.scripts.twistd from twisted.protocols import basic from twisted.internet import protocol, reactor from twisted.application import service, internet class MyChat(basic.LineReceiver): def connectionMade(self): print "Got new...

Django Template Slice - Reversing Order

Thanks to a very helpful hint from another question I learned I can limit the amount of values in a list by slicing it in the template as such: {% for comment in thread.comment_set.all|slice:":3" %} Now I would like to get the last 3 results of my comments so I figured a simple ":-3" or "-3" would do the trick, alas: Caught an except...

Remove whitespace in Python using string.whitespace

Python's string.whitespace is great: >>> string.whitespace '\t\n\x0b\x0c\r ' How do I use this with a string without resorting to manually typing in '\t|\n|... etc for regex? For example, it should be able to turn: "Please \n don't \t hurt \x0b me." into "Please don't hurt me." I'd probably want to keep the single spaces, but it'...

Tree Transformations Using Visitor Pattern

(Disclaimer: these examples are given in the context of building a compiler, but this question is all about the Visitor pattern and does not require any knowledge of compiler theory.) I'm going through Andrew Appel's Modern Compiler Implementation in Java to try to teach myself compiler theory (so no, this isn't homework) and I'm havin...

Tools for implementing a watchdog timer in python

I'm writing some code for testing multithreaded programs (student homework--likely buggy), and want to be able to detect when they deadlock. When running properly, the programs regularly produce output to stdout, so that makes it fairly straightforward: if no output for X seconds, kill it and report deadlock. Here's the function protot...

Serializing resultset returned from mysqldb in python

Can anyone please help me in serializing resultset returned using mysqldb in python? I get typeerror: datetime.date(2007, 11, 15) is not JSON serializable What is the best way to do serialize into Json object in python? I am using json.dumps(resultset) to serialize resultset... ...

Python login script

Hi All, I have the following script to logon to a url,but on submit in the webpage i call <input type=button value="go" onclick="Search()";> How to do the same in the following script instead of submit...... import urllib, urllib2, time username = "sumname" password = "test" interval = 10 data = {"username":username,"password":pass...

Referencing an old .lib in setup.py (or How can I convert an old .lib to a .a file)

I'm writing a python wrapper for an old proprietary system with header files, a .lib and some .dlls available to me on Windows. The library that is referenced is in .lib format (header files have references to Borland C & MSC) I've attempted to convert the .lib to a .a file with pexports -- it complains about not being able to load PE ...

How can I pass my ID and my password to a website in Python using Google App Engine?

Here is a piece of code that I use to fetch a web page HTML source (code) by its URL using Google App Engine: from google.appengine.api import urlfetch url = "http://www.google.com/" result = urlfetch.fetch(url) if result.status_code == 200: print "content-type: text/plain" print print result.content Everything is fine here, ...