python

Accessing a decorator in a parent class from the child in Python

Hi, how does one go about accessing a decorator from a base class in a child? I assumed (wrongly) that the ffg. would work: class baseclass(object): def __init__(self): print 'hey this is the base' def _deco(func): def wrapper(*arg): res = func(*arg) print 'I\'m a decorator. This is fabu...

What exactly does a non-shallow filecmp.cmp do?

I'm using Python 2.6.2. The docs for the filecmp module say: The filecmp module defines functions to compare files and directories, with various optional time/correctness trade-offs. and, of the filecmp.cmp function: filecmp.cmp(f1, f2[, shallow]) Compare the files named f1 and f2, returning True if they seem equal, False ...

How to add NOT NULL constraint on foreign keys in Web2py

I am having trouble in making my models to generate foreign keys as not null in Web2py. I have tried everything that I knew and all that I could find on the web. Here is a simple example: db = DAL('sqlite://storage.db') users=db.define_table('user', Field('name') ) cars=db.define_table('cars', Field('user', users, notnull=True), Field(...

Django database reconnect

Django's backend (firebird) reconnecting to database was fixed as here by disabling request finishing signal. It works with development server. But when project was deployed with mod_wsgi connections again reinitialize for each request. How to fix it? Thanks. p.s my connection is very expensive (about 1sec.) p.p.s sorry for my english....

How to remove duplicates in Links genrated using mechnize in Python?

Here is my code in python which Genrates a list of link objects. I want to remove duplicates form them. cb = list() for link in br.links(url_regex="inquiry-results.jsp"): cb.append(link) print set(cb) But It returns the error unhashable instance. link is something like this - Link( base_url='http://casesearch.courts.state...

How to merge lists of dictionaries

With lists of dictionaries such as the following: user_course_score = [ {'course_id': 1456, 'score': 56}, {'course_id': 316, 'score': 71} ] courses = [ {'course_id': 1456, 'name': 'History'}, {'course_id': 316, 'name': 'Science'}, {'course_id': 926, 'name': 'Geography'} ] What is the best way to combine them int...

Perform an action over 2 and 2 elements in a list

I have a list of numbers, say data = [45,34,33,20,16,13,12,3] I'd like to compute the difference between 2 and 2 items, (that is, for the above data I want to compute 45-34,33-20,16-13 and 12-3, what's the python way of doing that ? Also, more generally, how should I apply a function to 2 and 2 of these elements, that is, I want to c...

AttributeError - type object 'Services' has no attribute 'service_price'

Hi there, I'm trying to create something like an invoice program, to create invoices and calculate prices. I am still on the models part and I am trying to calculate all the services includes in a single invoice and update them in Invoices.subtotal. My problem is that I cannot pass the summary value of Services.service_price to Invoice...

Python can't import module named wsgi_soap from the soaplib

Hi! This code works on Debian under Python 2.5 but doesn't on Ubuntu under Python 2.6: from soaplib.wsgi_soap import SimpleWSGISoapApp On ubuntu under python 2.6 I get the error: from soaplib.wsgi_soap import SimpleWSGISoapApp ImportError: No module named wsgi_soap ...

python data attributes in sqlalchemy model

Hi, I'm getting myself into issues with python class attributes vs data attributes in my sqlalchemy model. This is a small example to demonstrate what's happening: # -*- coding: utf-8 -*- import cherrypy import sqlalchemy from sqlalchemy import create_engine from sqlalchemy import Table, Column, Integer, String, MetaData, ForeignKey fr...

Python base64 data decode and byte order convert

Hi, I am now using python base64 module to decode a base64 coded XML file, what I did was to find each of the data (there are thousands of them as for exmaple in "ABC....", the "ABC..." was the base64 encoded data) and add it to a string, lets say s, then I use base64.b64decode(s) to get the result, I am not sure of the result of the dec...

What is Python buffer type for?

There is a buffer type in python, but I don't know how can I use it. In the Python doc the description is: buffer(object[, offset[, size]]) The object argument must be an object that supports the buffer call interface (such as strings, arrays, and buffers). A new buffer object will be created which references the object argumen...

Extracting a tag value in BeautifulSoup when uanble to match by position or attributes.

I'm using BS to scrape a web page and i'm a little stuck with a small problem. Here's a snippet of HTML from the page. <span style="font-family: arial;"><span style="font-weight: bold;">Artist:</span> M.I.A.<br> </span> Once I've got the soup, how can i find this tag and get the artist name i.e. M.I.A. I cannot match the tag with the ...

Subprocess.Popen hangs with interactive programs when called from inside Django

Hi, I have written a small Django App, that executes an interactive program based on user input and returns the output as the result. But for some reason, the subprocess hangs. On verification of the logs I found that a place where a '\n' has to be given as repsonse to a challenge, the response seems to have never been made. Interesting...

Adding same text to two different lists

How can I add the same text(s) to two or more different lists? For example, this is what I am doing: >>> msg = 'Do it' >>> first = list() >>> second = list() >>> first.append(msg) >>> second.append(msg) Not only this is causing redundancy, I think it makes for poor code. Is there any way I can add the same text to two or more differe...

Importing my own modules in Google App Engine

Hi, I'm brand new to Google App Engine and have just been playing around with it, but for the life of me I don't understand how to import non-standard modules, and for that matter don't fully understand the app.yaml file's purposes. Essentially I want to import SimPy (a collection of ~15 python files) from my script file, but every com...

Problem using MySQLdb on OSX: symbol not found _mysql_affected_rows

This is related to a previous question. However, the main posted solution there is not working for me. I'm on Snow Leopard, using the 32-bit 5.1.49 MySQL dmg install. I'm using the built in python (apparently, as noted in the comments, my Python version is different), which appears to be 2.6.5 32-bit: Python 2.6.5 (r265:79359, Mar 24 ...

Dynamic class field creation before metaclass machinery

I'm trying to get rid of exec in a code similar to this: class A(object): for field in ['one', 'two', 'three']: exec '%s = "%s value"' % (field, field) ...so that: >>> A.one 'one value' >>> A.two 'two value' >>> A.three 'three value' EDIT: and also the requirement mentioned in the subject is met i.e. A.one is 'one value...

Which Actor model library/framework for python and Erlang-like?

Hi all, I am looking for a easy to learn Actor library or framework for Python 2.x I have tried Candygram and Twisted but I did not like none of them. I'd like something will be easy to extend to suppero Greenlet (= stackless python). Candygram is too old. Twisted is too complicated. Gevent: it is unclear if it can support Actors mod...

Comparing local file with remote file

Hi, I have the following problem ,I have a local zip file and a zip file located on a server. I need to check if the zip file on the server in different from the local one,if they are not I need to pull the new one from the server.My question is how do I compare them without downloading the file from the server and comparing them locally...