python

In Python how do I sort a list of dictionaries by values of the dictionary?

I got a list of dictionaries and want that to be sorted by a value of that dictionary. This [{'name':'Homer', 'age':39}, {'name':'Bart', 'age':10}] sorted by name, should become [{'name':'Bart', 'age':10}, {'name':'Homer', 'age':39}] ...

How to create a triple-join table with Django

Using Django's built in models, how would one create a triple-join between three models. For example: Users, Roles, and Events are the models. Users have many Roles, and Roles many Users. (ManyToMany) Events have many Users, and Users many Events. (ManyToMany) But for any given Event, any User may have only one Role. How can this b...

Is there a python package to interface with MS Cluster ?

I need to write a couple of python scripts to automate the installation of Microsoft Cluster Ressources. More specifically, I'll need to query MS Cluster to be able to get a list of ressources with their parameters. And I also need to be able to create resources and set their parameters. Is someone knows if there is a package/module....

Terminating a Python script

I am aware of the die() command in PHP which stops a script early, how can I do this in Python? ...

Sending mail via sendmail from python

If I want to send mail not via SMTP, but rather via sendmail, is there a library for python that encapsulates this process? Better yet, is there a good library that abstracts the whole 'sendmail -versus- smtp' choice? I'll be running this script on a bunch of unix hosts, only some of which are listening on localhost:25; a few of these ...

Is there a common way to check in Python if an object is any function type?

I have a function in Python which is iterating over the attributes returned from dir(obj), and I want to check to see if any of the objects contained within is a function, method, built-in function, etc. Normally you could use callable() for this, but I don't want to include classes. The best I've come up with so far is: isinstance(ob...

Random in python 2.5 not working?

I am trying to use the import random statement in python, but it doesn't appear to have any methods in it to use. Am I missing something? ...

How do I get the name of a python class as a string?

What method do I call to get the name of a class? ...

How to use form values from an unbound form

I have a web report that uses a Django form (new forms) for fields that control the query used to generate the report (start date, end date, ...). The issue I'm having is that the page should work using the form's initial values (unbound), but I can't access the cleaned_data field unless I call is_valid(). But is_valid() always fails on ...

Django -vs- Grails -vs- ???

I'm wondering if there's such a thing as Django-like ease of web app development combined with good deployment, debugging and other tools? Django is a very productive framework for building content-heavy sites; the best I've tried and a breath of fresh air compared to some of the Java monstrosities out there. However it's written in Py...

Undo with GTK TextView

I'm trying to keep dependencies to a minimum for a program I contribute to, it's a small text editor. GTK Textview doesn't seem to come with a built-in undo function. Is there any reference implementation I've been missing on so far? Is everyone writing their own undo function for their TextView widgets? I'll be happy about any sample ...

Which of these scripting languages is more appropriate for pen-testing?

First of all, I want to avoid a flame-war on languages. The languages to choose from are Perl, Python and Ruby . I want to mention that I'm confortable with all of them, but the problem is that I can't focus just on one. If for example , I see a cool Perl module, I have to try it out. If I see a nice Python app, I have to know how it's...

Best php/ruby/python e-commerce solution

I'm looking for an easy to skin and customize e-commerce package. I've been reading good reviews about Magento, but it seems to have problems with performance. I've tried osCommerce before and found it to be pretty painful to modify, but I hear zenCart is better... but the latest release of zenCart is nearly a year old, so not sure how...

VBA resource for Python programmer

I've written a lot of code in Python, and I'm very used to the syntax, object structure, and so forth of Python because of it. What's the best online guide or resource site to give me the basics, as well as lookup equivalent functions/features in VBA versus Python. For example, I'm having trouble equating a simple List in Python with s...

Which is faster, python webpages or php webpages?

Does anyone know how the speed of pylons(or any of the other frameworks) compares to a similar website made with php? I know that serving a python base webpage via cgi is slower than php because of its long start up every time. I enjoy using pylons and I would still use it if it was slower than php. But if pylons was faster than php, I...

What does BlazeDS Livecycle Data Services do, that something like PyAMF or RubyAMF not do?

I'm doing a tech review and looking at AMF integration with various backends (Rails, Python, Grails etc). Lots of options are out there, question is, what do the Adobe products do (BlazeDS etc) that something like RubyAMF / pyAMF don't? ...

'id' is a bad variable name in Python

Why is it bad to name a variable 'id' in Python? ...

iBATIS for Python?

At my current gig, we use iBATIS through Java to CRUD our databases. I like the abstract qualities of the tool, especially when working with legacy databases, as it doesn't impose its own syntax on you. I'm looking for a Python analogue to this library, since the website only has Java/.NET/Ruby versions available. I don't want to have...

What's the best way to calculate a 3D (or n-D) centroid?

As part of a project at work I have to calculate the centroid of a set of points in 3D space. Right now I'm doing it in a way that seems simple but naive -- by taking the average of each set of points, as in: centroid = average(x), average(y), average(z) where x, y and z are arrays of floating-point numbers. I seem to recall that ther...

OPENGL User Interface Programming

I'm developing a graphical application to present data (not a game but a real workhorse app). It needs to be cross platform, so I have chosen: python openGL (I need 3D, blending, textures etc) pyopengl wx/pywx - windowing, dialogs etc. The last component - WX - raises the question. I can put together a very nice looking app (the prot...