python

How to construct a web file browser?

Goal: simple browser app, for navigating files on a web server, in a tree view. Background: Building a web site as a learning experience, w/ Apache, mod_python, Python code. (No mod_wsgi yet.) What tools should I learn to write the browser tree? I see JavaScript, Ajax, neither of which I know. Learn them? Grab a JS example from t...

Django 1.0, using default password reset

I'm trying to use the password reset setup that comes with Django, but the documentation is not very good for it. I'm using Django 1.0 and I keep getting this error: Caught an exception while rendering: Reverse for 'mysite.django.contrib.auth.views.password_reset_confirm' with arguments '()' and keyword arguments ... in my urlconf I ...

Efficient python code for printing the product of divisors of a number

I am trying to solve a problem involving printing the product of all divisors of a given number. The number of test cases is a number 1 <= t <= 300000 , and the number itself can range from 1 <= n <= 500000 I wrote the following code, but it always exceeds the time limit of 2 seconds. Are there any ways to speed up the code ? from math...

Help me to port this NetHack function to Python please!

Hi, I am trying to write a Python function which returns the same moon phase value as in the game NetHack. This is found in hacklib.c. I have tried to simply copy the corresponding function from the NetHack code but I don't believe I am getting the correct results. The function which I have written is phase_of_the_moon(). The functio...

Operation on every pair of element in a list

Hello everyone, Using Python, I'd like to compare every possible pair in a list. Suppose I have my_list = [1,2,3,4] I'd like to do an operation (let's call it foo) on every combination of 2 elements from the list. The final result should be the same as foo(1,1) foo(1,2) ... foo(4,3) foo(4,4) My first thought was to iterate twice...

Missing 'Median' Aggregate Function in Django?

The Development version of Django has aggregate functions like Avg, Count, Max, Min, StdDev, Sum, and Variance (link text). Is there a reason Median is missing from the list? Implementing one seems like it would be easy. Am I missing something? How much are the aggregate functions doing behind the scenes? ...

What are some recommended resources and tutorials for learning the VTK library toolkit?

Apart from the books available from Kitware, I am looking for some links to any resources that could help in learning the VTK library. Preferably, with example code and tutorials. Google results have not been terribly informative for me. So I am asking here for links to VTK resources. ...

How to Change Mouse Cursor in PythonCard

How do I change the mouse cursor to indicate a waiting state using Python and PythonCard? I didn't see anything in the documentation. ...

Python performance question

How much of a difference are these two as far as performance? tmp = [] tmp.append(True) print tmp[0] And tmp = {} tmp[0] = True print tmp[0] ...

Flash-based file upload (swfupload) fails with Apache/mod-wsgi.

This question has been retitled/retagged so that others may more easily find the solution to this problem. I am in the process of trying to migrate a project from the Django development server to a Apache/mod-wsgi environment. If you had asked me yesterday I would have said the transition was going very smoothly. My site is up, acce...

Benefit of installing Django from .deb versus .tar.gz?

I'm starting Django development, and I can either install it from the .deb using $ apt-get install python-django on my Ubuntu machine, or I can download the .tar.gz from djangoproject.com, and start with that. What are the benefits and drawbacks of each approach? ...

how to get the function declaration or definitions using regex

I want to get only function prototypes like int my_func(char, int, float) void my_func1(void) my_func2() from C files using regex and python. Here is my regex format: ".*\(.*|[\r\n]\)\n" ...

Python: Getting file modification times with greater resolution than a second.

os.path.getmtime() and os.stat() seem to return values in whole seconds only. Is this the greatest resolution possible on either a Windows or OSX file system, or is there a way of getting greater resolution on file times? ...

String manipulation in Cython

I have code that does some very CPU-intensive string manipulations and I was looking for ways to improve performance. (EDIT: I'm doing stuff like finding longest common substring, running lots of regular expressions which might be better expressed as state machines in c, stripping comments from HTML, stuff like that.) I am currently lo...

Connect to a running instance of Visual Studio 2003 using COM, build and read output

For Visual Studio 6.0, I can connect to a running instance like: o = GetActiveObject("MSDev.Application") What prog ID do I use for Visual Studio 2003? How do I execute a 'Build Solution' once I have the COM object that references the VS2003 instance? How do I get the string contents of the build output window after executing the bui...

pygtk gui freezes with pyjack thread

Hello I have a program that records audio from firewire device (FA-66) with Jack connection. The interface is created with pygtk and the recording with py-jack (http://sourceforge.net/projects/py-jack/). The recording is done in a different thread because the GUI must be used at the same time for viewing results from the audio. The pro...

Method that gets called on module deletion in Python

Is there a method that I can add to my module, which will get called when destructing the class? Update: We have a simple class which has only static member functions and needs to clean up the database connection when unloading the module. was hoping there would be a __del__ method either for modules or classes that don't have instances...

copy worksheet from one spreadsheet to another

Is it possible to copy spreadsheets with gdata API or worksheets from one spreadsheet to other? For now i copy all cells from one worksheet to another. One cell per request. It is too slow. I read about "cell batch processing" and write this code: src_key = 'rFQqEnFWuR6qoU2HEfdVuTw'; dst_key = 'rPCVJ80MHt7K2EVlXNqytLQ' sheetcl = gdat...

Exicution of a OS command from a Python daemon

I've got a daemon.py with a callback. How should I make the handler function execute a OS command? ...

Efficient way of creating recursive paths Python

Hi I need a simple function to create a path in Python where the parent may or may not exist. From python documentation os.makedirs will fail if one of the parents exists. I have written the below method as which works by makes as many sub directories as necessary. Does this look efficient? def create_path(path): import os.path...