python

How can I improve this long-winded Python code?

I have a data structure like this: items = [ ['Schools', '', '', '32'], ['Schools', 'Primary schools', '', '16'], ['Schools', 'Secondary schools', '', '16'], ['Schools', 'Secondary schools', 'Special ed', '8'], ['Schools', 'Secondary schools', 'Non-special ed', '8'], ] It's a list of spending items. Some are aggreg...

Calling python script on MAC/Linux from Command line - passing arguments

Consider this setup and folder structure: c:\foo \bin\foo.bat \lib\foo.py I have foo.bat path added to my environment PATH, so I can call it from anywhere passing in some arguments: c:/>foo.bat -v foo.bat contains this code: @ECHO OFF "c:\foo\lib\foo.py" %1 %2 %3 %4 %5 %6 %7 %8 %9 This works fine in Windows. Now I ...

Creating a Maya UI

Hi all, I am creating a maya UI but when I try to run my loadobject button command twice after I run my replace_name button once in maya I get this error: cmds.textFieldButtonGrp(self.loadobject, e=True, text=select_objects[0]) RuntimeError: Hope someone could help me fix this. Thanks. import maya.cmds as cmds class MyUI: def _...

Why does updating a set in a tuple cause an error?

I have just tried the following in Python 2.6: >>> foo = (set(),) >>> foo[0] |= set(range(5)) TypeError: 'tuple' object does not support item assignment >>> foo (set([0, 1, 2, 3, 4]),) >>> foo[0].update(set(range(10))) >>> foo (set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]),) I have several questions here: Why does foo[0] |= set(range(5)) upda...

Identi.ca streaming api, libraries?

Has identi.ca a streaming API like stream.twitter.com? If it has, is there any Python library to implement that? Now I'm using tweepy, but I doesn't seem to have identi.ca support for streaming API. Thank you. ...

what is a range query

What is a range query over a kdtree and how is it done by python? ...

How to show that a script should be run as root in Linux

I am writing technical documentation for a smalll project I wrote in college. How do I show that script should be run with root privileges? My main question is what is the norm of depicting show a scenario? I can of course write that 'run the script with root privileges', but I thought I had ask here. Should I do : Run the script with...

[python] import png image as matrix?

Hi, I want to do some image processing using Python - is there a simple way to import .png image files as a matrix of greyscale/RGB values (possibly using PIL)? ...

python setuptool how can I add dependency for libxml2-dev and libxslt1-dev?

My application needs lxml >= 2.1, but to install lxml its requied to install libxml2-dev libxslt1-dev else it raises error while installing the lxml, is there a way that using python setup tool I can give this as dependency in my setup.py.... ...

Import all modules in django

In django is there way to import all modules ex: from project.models import * ex: from project1.models import * Can this be done with one statement ...

turbogears and mobile site

is it possible to develop mobile versions of webpages using turbogears.can someone please show me an example and how it is done.need it urgently.thanks ...

rotation of 2d shape clockwise direction

I am new to python and graphics but have programmed before. According to http://en.wikipedia.org/wiki/Transformation_matrix#Rotation , For rotation by an angle θ anticlockwise about the origin, the functional form is x' = xcosθ − ysinθ and y' = xsinθ + ycosθ But the following python code rotates it in the clockwise direction....

what is the next step ??

When I type "python" it displays: ActivePython 2.6.5.14 (ActiveState Software Inc.) based on Python 2.6.5 (r265:79063, Jul 4 2010, 21:05:58) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. This is what I get at the command line: >>> python create-application.py File "<stdin>...

matplotlib weirdness, it's not drawing my graph

What happened is I followed this demo, I modified it to suit my needs had it working, changed it to use a function to draw two graphs but now it doesn't work at all using plt.show() or plt.savefig() here's my code import csv import numpy as np import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt import matplotlib.m...

How to convert a binary file into a Long integer?

In python, long integers have an unlimited range. Is there a simple way to convert a binary file (e.g., a photo) into a single long integer? ...

How can I convert the time in a datetime string from 24:00 to 00:00 in Python?

I have a lot of date strings like Mon, 16 Aug 2010 24:00:00 and some of them are in 00-23 hour format and some of them in 01-24 hour format. I want to get a list of date objects of them, but when I try to transform the example string into a date object, I have to transform it from Mon, 16 Aug 2010 24:00:00 to Tue, 17 Aug 2010 00:00:00. W...

Getting started with Qooxdoo

i downloaded Qooxdoo, then ActivePython and installed it as in this tutorial http://qooxdoo.org/documentation/1.1/helloworld. When I follow the instructions I get the following results: C:\qooxdoo-1.1-sdk\tool\bin\create-application.py --name=custom --out=C: - this command opens a "create-application" wordfile. cd C:\custom inside c:\c...

How do I access base class variables through an instance of a child class in Python?

I wanted to know how to access to the super class’s variables with a object of child class If it makes any sense I add that some of the variables are defined in this __variable name way. Any time I want to access the variables with a child object. Python says the object with the type CHILE CLASS TYPE here is not defined. I wanted to kn...

Organizing files in tar bz2 file with python

I have about 200,000 text files that are placed in a bz2 file. The issue I have is that when I scan the bz2 file to extract the data I need, it goes extremely slow. It has to look through the entire bz2 file to fine the single file I am looking for. Is there anyway to speed this up? Also, I thought about possibly organizing the files in...

How can I find tag with regular expression. Python.

Possible Duplicate: RegEx match open tags except XHTML self-contained tags How can I find tag with regular expression. I have html like this: <div class='head'> Article TExt <div> <tag> Some ather text </tag> How mast looks like regular expression to find text inside tags DIV whith class 'head'? ...