python

Python - No handlers could be found for logger "OpenGL.error"

Okay, what is it, and why does it occur on Win2003 server, but not on WinXP. It doesn't seem to affect my application at all, but I get this error message when I close the application. And it's annoying (as errors messages should be). I am using pyOpenGl and wxPython to do the graphics stuff. Unfortunately, I'm a C# programmer that h...

Postgres - how to return rows with 0 count for missing data?

I have unevenly distributed data(wrt date) for a few years (2003-2008). I want to query data for a given set of start and end date, grouping the data by any of the supported intervals (day, week, month, quarter, year) in PostgreSQL 8.3 (http://www.postgresql.org/docs/8.3/static/functions-datetime.html#FUNCTIONS-DATETIME-TRUNC). The prob...

Read file as string in python

I'm using urllib2 to read in a page. I need to do a quick regex on the source and pull out a few variables. I'm new to python so I'm struggling to see how I use a file object (that urllib2 returns) to do this. ...

Python regex

I have a string like this that I need to parse into a 2D array: str = "'813702104[813702106]','813702141[813702143]','813702172[813702174]'" the array equiv would be: arr[0][0] = 813702104 arr[0][1] = 813702106 arr[1][0] = 813702141 arr[1][1] = 813702143 #... etc ... I'm trying to do this by REGEX. The string above is buried in an...

Installation problems with django-tagging

I am having problems using django-tagging. I try to follow the documentation but it fails at the second step Once you've installed Django Tagging and want to use it in your Django applications, do the following: Put 'tagging' in your INSTALLED_APPS setting. Run the command manage.py syncdb. The syncdb command create...

Format numbers in django templates

I'm trying to format numbers. Examples: 1 => 1 12 => 12 123 => 123 1234 => 1,234 12345 => 12,345 It strikes as a fairly common thing to do but I can't figure out which filter I'm supposed to use. Edit: If you've a generic Python way to do this, I'm happy adding a formatted field in my model. ...

Is it more efficient to use "import <module>" or "from <module> import <func>"?

Say I only needed to use findall() from the re module, is it more efficient to do: from re import findall or import re Is there actually any difference in speed/memory usage etc? ...

Ticking function grapher

Hello everyone, I am trying to figure out the following problem. I am building Yet another math function grapher, The function is drawn on its predefined x,y range, that's all good. Now I am working on the background and the ticking of X, Y axes (if any axes are shown). I worked out the following. I have a fixed width of 250 p The ti...

Django.contrib.flatpages without models

I have some flatpages with empty content field and their content inside the template (given with template_name field). Why I am using django.contrib.flatpages It allows me to serve (mostly) static pages with minimal URL configuration. I don't have to write views for each of them. Why I don't need the model FlatPage I leave the con...

Questions for python->scheme conversion

I currently am trying to write a python program using scheme semantics so I can later translate it into scheme without relying on a lot of pythonic stuff. I'm trying solve the sliding puzzle problem (where you have 9 slots and 8 tiles arranged in a square) using a*, depth first, and breadth first search algorithm. I did this ~11 years ...

Where do I go from here -- regarding programming?

I seem to be in a never ending tail spin of Linux, or not, Windows or not. Web programming or system programming. Python or PHP. I'am self teaching myself programming. But it seems I keep being torn about which way to go. Unfortunately it is always seemingly good reasons to get side tracked. You know the whole open source or proprietary...

How do I concisely implement multiple similar unit tests in the Python unittest framework?

I'm implementing unit tests for a family of functions that all share a number of invariants. For example, calling the function with two matrices produce a matrix of known shape. I would like to write unit tests to test the entire family of functions for this property, without having to write an individual test case for each function (pa...

Can I use Python to intercept global keystrokes in KDE?

I want to make a simple app, ideally in Python, that would run in the background on KDE, listening to all keystrokes being done by the user, so that the app goes to the foreground if a specific combination of keys is pressed. Is that doable? Can anyone point me to such resource? ...

Emitting headers from a tiny Python web-framework

I am writing a web-framework for Python, of which the goal is to be as "small" as possible (currently under 100 lines of code).. You can see the current code on github Basically it's written to be as simple to use as possible. An example "Hello World" like site: from pyerweb import GET, runner @GET("/") def index(): return "<stron...

Rounding float to the nearest factor ?

I have a small math problem I am trying to solve Given a number x and resolution y, I need to find the next x' with the required resolution. e.g. x = 1.002 y = 0.1 x'= 1.1 x = 0.348 y = 0.1 x'= 0.4 x = 0.50 y = 1 x'= 1 x = 0.32 y = 0.05 x'= 0.35 Is there any smart way of doing this in Python? ...

How do I get nose to discover dynamically-generated testcases?

This is a follow-up to a previous question of mine. In the previous question, methods were explored to implement what was essentially the same test over an entire family of functions, ensuring testing did not stop at the first function that failed. My preferred solution used a metaclass to dynamically insert the tests into a unittest.T...

mod_python.publisher always gives content type 'text/plain'

I've just set up mod python with apache and I'm trying to get a simple script to work, but what happens is it publishes all my html as plain text when I load the page. I figured this is a problem with mod_python.publisher, The handler I set it too. I searched through the source of it and found the line where it differentiates between 't...

Gauss-Legendre Algorithm in python

Hello! I need some help calculating Pi. I am trying to write a python program that will calculate Pi to X digits. I have tried several from the python mailing list, and it is to slow for my use. I have read about the Gauss-Legendre Algorithm, and I have tried porting it to Python with no success. I am reading from Here, and I would app...

AKS Primes algorithm in Python

A few years ago, it was proven that PRIMES is in P. Are there any algorithms implementing their primality test in Python? I wanted to run some benchmarks with a naive generator and see for myself how fast it is. I'd implement it myself, but I don't understand the paper enough yet to do that. ...

How to test django caching?

Is there a way to be sure that a page is coming from cache on a production server and on the development server as well? The solution shouldn't involve caching middleware because not every project uses them. Though the solution itself might be a middleware. Just checking if the data is stale is not a very safe testing method IMO. ...