python

build recent numpy on recent ubuntu

Hi How do I build numpy 1.5 on ubuntu 10.10? The instructions I found seems outdated or not clear. Thanks ...

Find and replace in CSV files with Python

Related to a previous question, I'm trying to do replacements over a number of large CSV files. The column order (and contents) change between files, but for each file there are about 10 columns that I want and can identify by the column header names. I also have 1-2 dictionaries for each column I want. So for the columns I want, I want...

Sharing model between Camelot and non-Camelot apps

I would like to share my data model between different Elixir/SQLAlchemy applications, one of which would be a Camelot UI and the others stuff like web interfaces and so on. They would all connect to the same underlying database. As far as I know, to build a Camelot app my model would do from camelot import blah and that would prevent it...

Java: automatic memoization

I have a few functions in my code where it makes much sense (seems even mandatory) to use memoization. I don't want to implement that manually for every function separately. Is there some way (for example like in Python) I can just use an annotation or do something else so I get this automatically on those functions where I want it? ...

Parsing command line arguments in a python script (getopt woes)

Ok, python newbie here. This is so elementary, I am almost embarrassed to post the question - yet still, I have spent more than a few minutes trying to get it to work - time to swallow my pride. Here is the script. Can anyone spot why it is not printing the passed arguments? import sys, getopt def usage(): print 'Unknown argument...

Non-blocking class in python (detached Thread)

Hello everyone... I'm trying to create a kind of non-blocking class in python, but I'm not sure how. I'd like a class to be a thread itself, detached from the main thread so other threads can interact with it. In a little example: #!/usr/bin/python2.4 import threading import time class Sample(threading.Thread): def __init__(sel...

Beautiful Soup findAll() on the results of a findall() returns TypeError

Hi I'm new to both Python and Beautiful soup. I'm trying to get the text only from a certain part of a table. But it seems the result of a findAll is not a BeautifulSoup type that I can run findAll on again. select = soup.find('table',{'id':"tp_section_1"}) print "got the right table" tissues = select.findAll('td',{"class":re.compile("t...

Django's equivalent to Rails 5 min blog demo

Some how some way I'm trying to get out of Ruby because things are just working and I don't necessarily know why. I'm taking the forest for the trees approach by which I mean I'm trying to get perspective by learning a new language; Python/Django seems to be the right way to go. The first application I built in Rails was from the 5 min ...

How to remove the unselected item in a select and radio input in Django

If a model's field is a choice or foreign key, the widget on the page is a select input or radios if you specify that. Django places "---------" in the first item as an unselected value. How can I override it or even remove it? I remember reading the way to do it but can't find it any more. ...

What does raise in Python raise?

Consider the following code: try: raise Exception("a") except: try: raise Exception("b") finally: raise This will raise Exception: a. I expected it to raise Exception: b (need I explain why?). Why does the final raise raise the original exception rather than (what I thought) was the last exception raised? ...

python decimals - rounding to nearest whole dollar (no cents) - with ROUND_HALF_UP

I'm trying to use Decimal.quantize() to achieve the following: - For any amount of money, expressed as a python decimal of default precision, I want to round it using decimal.ROUND_HALF_UP so that it has no cents after rounding. For example, given 1.25, I'm trying to obtain 1.00 (signifying no cents) given 1.49 I'm trying to obtain 1....

Python reclaiming memory after deleting items in a dictionary

I have a relatively large dictionary in Python and would like to be able to not only delete items from it, but actually reclaim the memory back from these deletions in my program. I am running across a problem whereby although I delete items from the dictionary and even run the garbage collector manually, Python does not appear to be fr...

xapian-bindings python compatibility

hello, i am able to get xapian working as expected with python on my development server but i am having issues with my web server. i keep running into this error: import xapian Traceback (most recent call last): File "", line 1, in File "/home/x/lib/python2.6/xapian/init.py", line 28, in ...

C / Python ctypes shared object introspection libraries/techniques.

Hi, I was looking for a way to list .text section defined symbols on a C shared object loaded on a python program using the ctypes wrapper. In other words, i am trying to get a list of defined functions on a CDLL loaded object. If there is no way to do this with ctypes or library ( or python binding ), another option is a python elf pa...

elegant way to match two wildcarded strings

I'm OCRing some text from two different sources. They can each make mistakes in different places, where they won't recognize a letter/group of letters. If they don't recognize something, it's replaced with a ?. For example, if the word is Roflcopter, one source might return Ro?copter, while another, Roflcop?er. I'd like a function that r...

Python "++" operator doesn't work

Possible Duplicate: Python: Behaviour of increment and decrement operators Hi, I've tried this. ++num and the num doesn't change at all, always show the value when initialized if I change ++num to num+=1 then it works. So, my question is how that ++ operator works? ...

Python lxml.html linebreaks?

Im using lxml.html.cleaner to clean html from an input text. how can i change \n to <br /> in lxml.html? ...

Pylons, cookies not being destroyed

I am trying to remove a cookie called "session" to logout a user. request.cookies.pop('session', None) response.set_cookie('session', '', max_age=-100, domain='.example.org') response.set_cookie('session', '', max_age=-100, domain='www.example.org') response.delete_cookie('session', '', domain='.example.org') response.delete_cookie('ses...

Python MySQLdb string substitution without added quotations

I'd like to use string substitution for a comma-separated list, such as: query = """SELECT id, name, image_id FROM users WHERE id IN (%s) """ values = (','.join(uids)) results = dbc.getAll(query, values This executes the query: SELECT id, name, image_id FROM users WHERE id IN ('1,2,3') Which does no...

What is the Python equivalent of Perl's backticks?

Possible Duplicate: Equivalent of Backticks in Python When I want to write directly to the command prompt in Perl, I can do something like this: Perl File test.pl: $directory = `dir`; print $directory; Which would output something like.. C:\Documents and Settings\joslim\Desktop>perl test.pl Volume in d...