python

how convert list of int to list of tuples

I want to convert a list like this l1 = [1,2,3,4,5,6,7,8] to l2 = [(1,2),(3,4),(5,6),(7,8)] because want to loop for x,y in l2: draw_thing(x,y) ...

Django: Extending Querysets / Connect multiple filters with OR

Hi! I have to work with a queryset, that is already filtered, eg. qs = queryset.filter(language='de') but in some further operation i need to undo some of the already applied filtering, eg not to take only the rows with language='de' but entries in all languages. Is there a way to apply filter again and have the new parameters connected ...

Django Year/Month based posts archive

Hello, i'm new to Django and started an application, i did the models, views, templates, but i want to add some kind of archive to the bottom of the page, something like this http://www.flickr.com/photos/ionutgabriel/3990015411/. So i want to list all years and next to them all the months from that year. The months who have posts to ...

Setting mod_python's interperter

I have mod_python installed on a debian box with python 2.4 and 2.6 installed. I want mod_python to use 2.6 but it is finding 2.4. How can set it to use the other version. ...

Not able to access google spreadsheet from app engine: "Moved Temporarily"?

As of a couple of days ago I was able to access my google spreadsheets from an app (in app engine), but today it is broken. Namely, I could name= "name of my spreadsheet" self.client = gdata.spreadsheet.text_db.DatabaseClient() self.client.GetDatabases(name=name) and it worked. In fact, that still works when I run with the dev_appser...

How do I import a COM object namespace/enumeration in Python?

I'm relatively new to programming/python, so I'd appreciate any help I can get. I want to save an excel file as a specific format using Excel through COM. Here is the code: import win32com.client as win32 def excel(): app = 'Excel' x1 = win32.gencache.EnsureDispatch('%s.Application' % app) ss = x1.Workbooks.Add() sh...

psyco complains about unsupported opcode 54, what is it?

The Psyco log output look like this: 21:08:47.56 Logging started, 10/29/09 %%%%%%%%%%%%%%%%%%%% 21:08:47.56 unsupported opcode 54 at create_l0:124 % % 21:08:47.56 unsupported opcode 54 at create_lx:228 % % the lines in question class File: def __init__(self, path, head...

Python on AIX: What are my options?

I need to make some Python applications for a work project. The target platform is AIX 5.3. My question is: What version of Python should I be using? My requirements are: The Python version must be easy to install on the target machines. Others will do that according to instructions that I write, so no compiling from source or anythi...

How to deploy Python to Windows users?

I'm soon to launch a beta app and this have the option to create custom integration scripts on Python. The app will target Mac OS X and Windows, and my problem is with Windows where Python normally is not present. My actual aproach is silently run the Python 2.6 install. However I face the problem that is not activated by default and t...

How to run django unit-tests on production database?

Hi, i'm starting the TDD development attitude and am writting unit-tests for my django application. I'm aware of fixtures and know that's the way tests should be executed, but for a given test i do need to execute it on the whole database, and json fixture for 10+ million row database is not something i'd like to handle, moreover, this ...

How to configure format of Python 2.3 logging messages?

In Python 2.4 and later, configuring the logging module to have a more basic formatting is easy: logging.basicConfig(level=opts.LOGLEVEL, format="%(message)s") but for applications which need to support Python 2.3 it seems more difficult, because the logging API was overhauled in Py2.4. In particular, basicConfig doesn't take any argum...

Is there a way to know if a list of elements is on a larger list without using 'in' keyword?

I want to do this. I have two python lists, one larger than the other and I want to know is there is a way to check if the elements of the smaller list are in the big list in the exact same order for example: small_list = [4,2,5] big_list = [1,2,5,7,2,4,2,5,67,8,5,13,45] I tried using the in keyword but It did not worked :'( ...

problem when re-running program

I have a fairly simple python loop that calls a few functions, and writes the output to a file. To do this is creates a folder, and saves the file in this folder. When I run the program the first time with a unique file name, it runs fine. However, if I try to run it again, it will not work and I do not understand why. I am quite certai...

referencing a key/value in django-templates after applying a filter

say I have the following list that I provide to a django template stuff= [ { 'a':2 , 'b':4 } , { 'a',7} ] I want to access the 'a' attribute of the first element. I can't quite get the syntax right. {{stuff|first}} gives me the first element, but {{stuff|first.a}} is a dead end ( and weird ) and I can't seem to find a attribute...

Adapt an existing database to a django app

I have a Postgresql databese with data. I want to create a django app with that database. How can i import the tables to django models and/or views? ...

How can I use Microsoft Word's spelling/grammar checker programmatically?

I want to process a medium to large number of text snippets using a spelling/grammar checker to get a rough approximation and ranking of their "quality." Speed is not really of concern either, so I think the easiest way is to write a script that passes off the snippets to Microsoft Word (2007) and runs its spelling and grammar checker o...

Correct way to access related objects

Hi, I have the following models class Person(models.Model): name = models.CharField(max_length=100) class Employee(Person): job = model.Charfield(max_length=200) class PhoneNumber(models.Model): person = models.ForeignKey(Person) How do I access the PhoneNumbers associated with an employee if I have the employee id? Cu...

Python question on elementwise operation

I have two srtings of integer a=[-1,0,-1,0,1] and b=[1] and i want to subtract b from a as elementwise operation but the answer shoud be string contaning element -1 or 0 or 1 ...

Getting Easting & Northing Values from geopy

I have a table full of longitude/ latitude pairs in decimal format (e.g., -41.547, 23.456). I want to display the values in "Easting and Northing"/ UTM format. Does geopy provide a way to convert from decimal to UTM? I see in the code that it will parse UTM values, but I don't see how to get them back out and the geopy Google Group has g...

How to encode an RSA key using PKCS12 in Python?

I'm using Python (under Google App Engine), and I have some RSA private keys that I need to export in PKCS#12 format. Is there anything out there that will assist me with this? I'm using PyCrypto/KeyCzar, and I've figured out how to import/export RSA keys in PKCS8 format, but I really need it in PKCS12. Can anybody point me in the right...