python

How can we change a wx.MenuBar background and foreground colour using wxpython?

Hello, I want to change the wxpython menubar colours. How can I do it? Thanks in advance :) ...

How to accept localized date format (e.g dd/mm/yy) in a DateField on an admin form ?

Is it possible to customize a django application to have accept localized date format (e.g dd/mm/yy) in a DateField on an admin form ? I have a model class : class MyModel(models.Model): date = models.DateField("Date") And associated admin class class MyModelAdmin(admin.ModelAdmin): pass On django administration ...

Check if a MediaWiki page exists (Python)

I'm working on a Python script that transforms this: foo bar Into this: [[Component foo]] [[bar]] The script checks (per input line) if the page "Component foo" exists. If it exists then a link to that page is created, if it doesn't exist then a direct link is created. The problem is that I need a quick & cheap way to check if a l...

How to print a range with decimal points in Python?

I can print a range of numbers easily using range, but is is possible to print a range with 1 decimal place from -10 to 10? e.g -10.0, -9.9, -9.8 all they way through to +10? ...

How can I use Python with Mechanize for posting multipart/form-data?

Hi there! I am using http://pypi.python.org/pypi/mechanize/0.1.11 for programmatic web browsing, I want to be able to upload files to servers the same way the browser does (by sending the content as multipart/form-data, defined in RFC2388) Is this possible with mechanize, can you show me an example? Thanks! ...

How to remove lowercase sentence fragments from text?

Hello: I'm tyring to remove lowercase sentence fragments from standard text files using regular expresions or a simple Perl oneliner. These are commonly referred to as speech or attribution tags, for example - he said, she said, etc. This example shows before and after using manual deletion: Original: "Ah, that's perfectly tr...

Python 3: Most efficient way to create a [func(i) for i in range(N)] list comprehension

Say I have a function func(i) that creates an object for an integer i, and N is some nonnegative integer. Then what's the fastest way to create a list (not a range) equal to this list mylist = [func(i) for i in range(N)] without resorting to advanced methods like creating a function in C? My main concern with the above list comprehens...

Disable browser caching in pylons

I'm have an action /json that returns json from the server. Unfortunately in IE, the browser likes to cache this json. How can I make it so that this action doesn't cache? ...

How to check the existence of a row in SQLite with Python?

I have the cursor with the query statement as follows: cursor.execute("select rowid from components where name = ?", (name,)) I want to check for the existence of the components: name and return to a python variable. How do I do that? ...

Printing Stdout In Command Line App Without Overwriting Pending User Input

In a basic Unix-shell app, how would you print to stdout without disturbing any pending user input. e.g. Below is a simple Python app that echos user input. A thread running in the background prints a counter every 1 second. import threading, time class MyThread( threading.Thread ): running = False def run(self): self....

Save memory in Python. How to iterate over the lines and save them efficiently with a 2million line file?

I have a tab-separated data file with a little over 2 million lines and 19 columns. You can find it, in US.zip: http://download.geonames.org/export/dump/. I started to run the following but with for l in f.readlines(). I understand that just iterating over the file is supposed to be more efficient so I'm posting that below. Still, wit...

Getting CPU temperature using Python?

How do I retrieve the temperature of my CPU using Python? (Assuming I'm on Linux) ...

How do I find the length of media with gstreamer?

How do I find the playback time of media with gstreamer? ...

Compiler options wrong with python setup.py

I'm trying to install matplotlib on my mac setup. I find that setup.py has inaccurate flags, in particular the isysroot points to an earlier SDK. Where does setup.py get its info and how can i fix it? I'm on MacOS 10.5.8, XCode 3.1.2 and Python 2.6 (default config was 2.5) ...

Python + FastCGI

I'm looking for recommendations on a library to use for a FastCGI server in Python. ...

Formatting floats in Python without superfluous zeros

How to format a float so it does not containt the remaing zeros? In other words, I want the resulting string to be as short as possible..? Like: 3 -> "3" 3. -> "3" 3.1 -> "3.1" 3.14 -> "3.14" 3.140 -> "3.14" ...

How to bind an ip address to telnetlib in Python

The code below binds an ip address to urllib, urllib2, etc. import socket true_socket = socket.socket def bound_socket(*a, **k): sock = true_socket(*a, **k) sock.bind((sourceIP, 0)) return sock socket.socket = bound_socket Is it also able to bind an ip address to telnetlib? ...

warning in python with MySQLdb

hi, when I use MySQLdb get this message: /var/lib/python-support/python2.6/MySQLdb/__init__.py:34: DeprecationWarning: the sets module is deprecated from sets import ImmutableSet I try filter the warning with import warnings warnings.filterwarnings("ignore", message="the sets module is deprecated from sets import ImmutableS...

Python Least-Squares Natural Splines

I am trying to find a numerical package which will fit a natural spline which minimizes weighted least squares. There is a package in scipy which does what I want for unnatural splines. import numpy as np import matplotlib.pyplot as plt from scipy import interpolate, randn x = np.arange(0,5,1.0/6) xs = np.arange(0,5,1.0/500) y = np....

What is the relationship between docutils and Sphinx?

There seems to be a plethora of documentation tools for Python. Another one that I've run across is epydoc. It seems like Sphinx is the de facto standard, because it's used to generate the official Python docs. Can someone please sort out the current state of Python's documentation tools for me? ...