python

Django passing a model instance to slightly different model

I'm writing an django app for a project where everybody can change articles but the changes that users commit have to be viewed by someone before they go online. So you see it is a bit like the system used by wikipedia. class Content(models.Model): tp = models.DateTimeField(auto_now_add=True) topic = models.CharField(max_length=...

Python Decorator Problem with Docstrings

I have a problem using docstrings with decorators. Given the following example: def decorator(f): def _decorator(): print 'decorator active' f() return _decorator @decorator def foo(): '''the magic foo function''' print 'this is function foo' help(foo) Now the help doesn't show me the docstring of foo...

Openlayers + Mapnik + Tilecache configuration problem

Hi All, I am trying to setup Mapnik + tilecache but can't see any tiles in the browser when I set bbox parameters in both Tilecache.cfg and Openlayers but when I don't specify the bbox everything works fine and I can see actual map tiles. I was wondering if anyone can point out the problem in the code. I think I have tried everything (...

Virtualenv: Where do I put stuff?

What sort of directory structure should one follow when using virtualenv? For instance, if I were building a WSGI application and created a virtualenv called foobar I would start with a directory structure like: /foobar /bin {activate, activate.py, easy_install, python} /include {python2.6/...} /lib {python2.6/...} O...

growing matrices columnwise in numpy

In pure python you can grow matrices column by column pretty easily: data = [] for i in something: newColumn = getColumnDataAsList(i) data.append(newColumn) numpy's array doesn't have the append function. The hstack function doesn't work on zero sized arrays, thus the following won't work: data = numpy.array([]) for i in some...

String preallocation in numpy.arrays

>>> import numpy as np >>> a = np.array(['zero', 'one', 'two', 'three']) >>> a[1] = 'thirteen' >>> print a ['zero' 'thirt' 'two' 'three'] >>> As you can see, the second element has been truncated to the maximum number of characters in the original array. Is it possible to workaround this problem? ...

How do I copy wsgi.input if I want to process POST data more than once?

In WSGI, post data is consumed by reading the file-like object environ['wsgi.input']. If a second element in the stack also wants to read post data it may hang the program by reading when there's nothing more to read. How should I copy the POST data so it can be processed multiple times? ...

Python Vs RoR : on Size

I am planning to do a small web application that will be distributed as a single installable. I have plans to develop this application in either Python/Django or RoR. (I am a Java/C++ programmer, hence both these languages are new to me). My main concern is about the size and simplicity of final installable (say setup.exe). I want it t...

Possible to use Mathematica from other programming languages (python/C#) ?

Is it possible to use Mathematica's computing capabilities from other languages? I need to do some complex operations (not necessarily symbolic, btw), and it'd be pretty sweet to be able to just call Mathematica's functions or running Mathematica's code right from my python/c#'s program. Is it possible? ...

Any python Support Vector Machine library around that allows online learning?

I do know there are some libraries that allow to use Support vector Machines from python code, but I am looking specifically for libraries that allow one to teach it online (this is, without having to give it all the data at once). Are there any? ...

What is the most efficent way to implement concurrency in Python?

In a cluster environment using Python what is the least expensive way to develop a concurrent application or what is the pro / con of the various options? ...

Python - Most useful lists-comprehension construction

What Python's user-made list-comprehension construction is the most useful? I have created the following two quantifiers, which I use to do different verification operations: def every(f, L): return not (False in [f(x) for x in L]) def some(f, L): return True in [f(x) for x in L] an optimized versions (requres Python 2.5+) was propo...

Python - Strip all drive letters from csv file and replace with Z:

Here is the code example. Basically output.csv needs to remove any drive letter A:-Y: and replace it with Z: I tried to do this with a list (not complete yet) but it generates the error: TypeError: expected a character buffer object #!/usr/bin/python import os.path import os import shutil import csv import re # Create the videos direct...

import from {in,out}side of a packages

Hi there ! I have a project I build on a library I'm building in parallel. The structure is the following : project/ main.py MyLibrary/ __init__.py --> empty Module1.py --> contain the class Class1 Module2.py --> contain the class Class2 Module3.py --> contain the class Class3 ... I need to import the ...

wxPython. Create a panel with four static sized boxes.

I'm trying to create a panel, with four boxes containing some data. These four boxes should have a predefined static size. What I have so far is four boxes that is overlapping to some extent. Any ideas? Code: import wx class MyFrame(wx.Frame): def __init__(self, *args, **kwargs): wx.Frame.__init__(self, *args, **kwargs) self.p...

How do I unit test Django views on the Google App Engine?

I am struggling to run unit tests using the Django Client class on the Google App Engine. I downloaded GAEUnit (v2.0a for Django) and I am trying to use that as my testing framework (maybe I should rather be using something else?) I copy all the GAEUnit files into my project root as instructed, and I modify my app.yaml file. Currently a...

Function not being called in Python, why? and how can I solve it?

Hello, I am currently working on python/django site, at the moment I have a template that looks like this {% extends "shopbase.html" %} {% block pageid %}products{% endblock %} {% block right-content %} <img src="{{MEDIA_URL}}/local/images/assets/products.png" alt="Neal and Wolf News" class="position"/> <div class="products"> ...

Create a new Tuple with one element modified

(I am working interactively with a WordprocessingDocument object in IronPython using the OpenXML SDK, but this is really a general Python question that should be applicable across all implementations) I am trying to scrape out some tables from a number of Word documents. For each table, I have an iterator that is giving me table row ob...

Python 3 - pull down a file object from a web server over a proxy (no-auth)

I have a very simple problem and I am absolutely amazed that I haven't seen anything on this specifically. I am attempting to follow best practices for copying a file that is hosted on a webserver going through a proxy server (which does not require auth) using python3. i have done similar things using python 2.5 but I am really coming...

Designing a multi-process spider in Python

I'm working on a multi-process spider in Python. It should start scraping one page for links and work from there. Specifically, the top-level page contains a list of categories, the second-level pages events in those categories, and the final, third-level pages participants in the events. I can't predict how many categories, events or pa...