python

Going Open (almost): Moving from MS/ASP to LIN/Py

I'm doing a case study (well, hoping to) on a migration from Win/ASP/SQLServer to a Linux/Pylons/Pgsql codebase. I was just wondering if anyone has any thoughts, pointers or experience in making such a dramatic shift. ...

How to match columns in MySQL.

Everyone knows the "=" sign. SELECT * FROM mytable WHERE column1 = column2; However, what if I have different contents in column1 and column2...but they are VERY similar? (maybe off by a space, or have a word that's different). Is it possible to: SELECT * FROM mytable WHERE ....column matches column2 with .4523423 "Score"... I bel...

Python object that monitors changes in objects

I want a Python object that will monitor whether other objects have changed since the last time they were checked in, probably by storing their hash and comparing. It should behave sort of like this: >>> library = Library() >>> library.is_changed(object1) False >>> object1.change_somehow() >>> library.is_changed(object1) True >>> librar...

Building Django app using Comet/Orbited on Apache, use mod_wsgi or mod_python?

Building a Django app on a VPS. I am not very experienced with setting up my own server, but I decided to try a VPS this time around. I have been doing a bunch of research to learn how to "properly" setup a LAMPython server using the Apache worker MPM. Naturally, the mod_python vs mod_wsgi debate came up. Reading Graham Dumpleton's ...

Python noob question: simple syntax error

I'm not sure if this site is for dumb troubleshooting questions, but I figure this will take someone 2 seconds. My Code: #!/usr/bin/env python def Runaaall(aaa): Objects9(1.0, 2.0) def Objects9(aaa1, aaa2): If aaa2 != 0: print aaa1 / aaa2 The error I receive: $ python test2.py File "test2.py", line 7 If aaa2 != 0: print...

Efficient way to convert strings from split function to ints in Python

I have a string of data with the following format: xpos-ypos-zoom (i.e. 8743-12083-15) that I want to split up and store in the variables xpos, ypos, and zoom. Since I need to do some calculations with these number I'd like to convert them to integers right from the beginning. Currently, the way I'm doing this is with the following code:...

Python multiprocessing: restrict number of cores used

I want to know how to distribute N independent tasks to exactly M processors on a machine that has L cores, where L>M. I don't want to use all the processors because I still want to have I/O available. The solutions I've tried seem to get distributed to all processors, bogging down the system. I assume the multiprocessing module is the...

How to read .ARC files from the Heritrix crawler using Python?

I looked at the Heritrix documentation website, and they listed a Python .ARC file reader. However, it is 404 not found when I clicked on it. http://crawler.archive.org/articles/developer%5Fmanual/arcs.html Does anyone else know any Heritrix ARC reader that uses Python? (I asked this question before, but closed it due to inaccuracy) ...

Preempting __del__ hmmm

Hi SO's I need to preempt __del__ and I want to know what is the right way to do this. Basically my question in code is this.. class A: def __init__(self): self.log = logging.getLogger() self.log.debug("In init") self.closed = False def close(self): self.log.debug("Doing some magic") se...

How can I read how many pixels an image has in Python

Possible Duplicate: How to check dimensions of all images in a directory using python? I was wondering if somebody knows how can I read an image total amount of pixels in a python sript. Could you provide and example? Thanks a lot. ...

Ensure that only one instance of a class gets run

Hi SO's I have an underlying class which I want to place in some code. I only want it to be instantiated or started once for a given app although it might be called many times.. The problem with the code below is that LowClass is started over and over again. I only want it to start once per test.. import logging class LowClass: ...

Python datetime subtraction - wrong results?

I must be doing something wrong here, any ideas? >>> (datetime.datetime(2008,11,7,10,5,14)-datetime.datetime(2008,11,6,9,30,16)).seconds 2098 It should be getting more than that many seconds. ...

Python callback with SWIG wrapped type

I'm trying to add a python callback to a C++ library as illustrated: template<typename T> void doCallback(shared_ptr<T> data) { PyObject* pyfunc; //I have this already PyObject* args = Py_BuildValue("(O)", data); PyEval_CallObject(pyfunc,args); } This fails because data hasn't gone through swig, and isn't a PyObject. I tried...

How can I check that a column in a tab-delimited file has valid values?

I have a large file named CHECKME which is tab delimited. There are 8 columns in each row. Column 4 is integers. By using Perl or Python, is it possible to verify that each row in CHECKME has 8 columns and that column 4 is an integer? ...

Python - Twisted and Unit Tests

I'm writing unit tests for a portion of an application that runs as an HTTP server. The approach I have been trying to take is to import the module that contains the HTTP server, start it. Then, the unit tests will use urllib2 to connect, send data, and check the response. Our HTTP server is using Twisted. One problem here is that I'...

Sorting strings with integers and text in Python.

I'm making a stupid little game that saves your score in a highscores.txt file. My problem is sorting the lines. Here's what I have so far. Maybe an alphanumeric sorter for python would help? Thanks. import os.path import string def main(): #Check if the file exists file_exists = os.path.exists("highscores.txt") scor...

Python on multiprocessor machines: multiprocessing or a non-GIL interpreter

This is more a style question. For CPU bound processes that really benefit for having multiple cores, do you typically use the multiprocessing module or use threads with an interpreter that doesn't have the GIL? I've used the multiprocessing library only lightly, but also have no experience with anything besides CPython. I'm curious w...

python pdb not breaking in files properly?

Hi Folks, I wish I could provide a simple sample case that occurs using standard library code, but unfortunately it only happens when using one of our in-house libraries that in turn is built on top of sql alchemy. Basically, the problem is that this break command: (Pdb) print sqlalchemy.engine.base.__file__ /prod/eggs/SQLAlchemy-0.5....

Using Sphinx to write personal websites and blogs

Sphinx is a Python library to generate nice documentation from a set of ReST formatted text files. I wonder if any one has written Sphinx plugins to make it generate personal websites and blogs. Especially for blogs, there needs to be a way to automatically list posts chronologically and generate a RSS feed. One needs to write a Sphinx...

Generate pretty diff html in Python

I have two chunks of text that I would like to compare and see which words/lines have been added/removed/modified in Python (similar to a Wiki's Diff Output). I have tried difflib.HtmlDiff but it's output is less than pretty. Is there a way in Python (or external library) that would generate clean looking HTML of the diff of two sets...