python

"painting" one array onto another using python / numpy

I'm writing a library to process gaze tracking in Python, and I'm rather new to the whole numpy / scipy world. Essentially, I'm looking to take an array of (x,y) values in time and "paint" some shape onto a canvas at those coordinates. For example, the shape might be a blurred circle. The operation I have in mind is more or less identi...

Choice of database for a Django-based RSS application?

I'm planning a web application using Django, and it's based on a big pile of data from RSS feeds. What would be the best database to use to store the content of a lot of posts and metadata, as well as data about how each user relates to each post? I've heard that the consensus is that ZODB is too slow, but it'd be handy to have a databa...

How to add clickable links to a field in Django admin?

Hi, I have this admin.py class LawyerAdmin(admin.ModelAdmin): fieldsets = [ ('Name', {'fields': ['last', 'first', 'firm_name', 'firm_url', 'school', 'year_graduated']}), ] list_display = ('last', 'first', 'school', 'year_graduated', 'firm_name', 'firm_url') list_filter = ['school', 'year_graduated'] search...

Checking if a website is up via Python

By using python, how can I check if a website is up? From what I read, I need to check the "HTTP HEAD" and see status code "200 OK", but how to do so ? Cheers Related How do you send a HEAD HTTP request in Python? ...

Mako templates use old version until I manually update template files

I periodically get this problem where all of a sudden mako is using old versions of templates, and it's not until I manually go and update the template files that they'll use the current version. I'm using ./manage.py runserver I think it's usually after I update using source control, but it's intermittent, and I can't reliably reprod...

Parsing an html file and adding found images to a zip file

I am trying to parse an html for all its img tags, download all the images pointed to by src, and then add those files to a zip file. I would prefer to do all this in memory since I can guarantee there won't be that many images. Assume the images variable is already populated from parsing the html. What I need help with is getting the i...

tornado - transferring a file to cdn without blocking

I have the nginx upload module handling site uploads, but still need to transfer files (let's say 3-20mb each) to our cdn, and would rather not delegate that to a background job. What is the best way to do this with tornado without blocking other requests? Can i do this in an async callback? ...

Python: intercept a class loading action

Summary: when a certain python module is imported, I want to be able to intercept this action, and instead of loading the required class, I want to load another class of my choice. Reason: I am working on some legacy code. I need to write some unit test code before I start some enhancement/refactoring. The code imports a certain module ...

Suspicious Operation Django

Hello, I've been running into a problem while trying to delete uploaded images. The error is along these lines: SuspiciousOperation: Attempted access to '/media/artists/12-stones/154339.jpg' denied. After reading around it looks like the error is due to the fact that it's looking for the image in the wrong place (notice first slash...

Does Python have any for loop equivalent (not foreach)

Python's iterators are great and all, but sometimes I really do want a C-style for loop - not a foreach loop. For example, I have a start date and an end date and I want to do something for every day in that range. I can do this with a while loop, of course: current = start while current <= finish: do_stuff(current) ...

Matplotlib PyQt-Widget plot() resets autoscale

Hello, i am using a Matplotlib figure as widget, in a PyQt4 programm. Everything works, except "set_autoscale_on(False)". Everytime i call a figure axes to plot something, it forgets its autoscale status. Here some code, with axs a subplot of a figure: print axs.get_autoscale_on() print axs.get_autoscaley_on() p...

Distributing Python programs

How do I let my friends use my Python programs? They don't have python installed, but they can use command line programs. I don't have the skill to write GUI. Let, say I am writing some calculus calculator, with a lot of custom modules and files. How do I share it? ...

Is it worth learning Python over Ruby and PHP for Web Development?

Is it worth learning Python over Ruby and PHP for Web Development? If so why? Thank you in advance. EDIT: Related on StackOverflow: Should I learn Ruby or Python? Django or RoR Rails or Django? (or something else?) Ruby on Rails versus Python What are the biggest differences between Python and Ruby from a philosophical perspective ...

pyyaml: dumping without tags

I have >>> import yaml >>> yaml.dump(u'abc') "!!python/unicode 'abc'\n" But I want >>> import yaml >>> yaml.dump(u'abc', magic='something') 'abc\n' What magic param forces no tagging? ...

Is it Pythonic to check function argument types?

I know, type checking function arguments is generally frowned upon in Python, but I think I've come up with a situation where it makes sense to do so. In my project I have an Abstract Base Class Coord, with a subclass Vector, which has more features like rotation, changing magnitude, etc. Lists and tuples of numbers will also return Tr...

what does classmethod has done,who can give me a simple code example,thanks

in django.utils.tree.py def _new_instance(cls, children=None, connector=None, negated=False): obj = Node(children, connector, negated) obj.__class__ = cls return obj _new_instance = classmethod(_new_instance) i don't know what classmethod does Please try to use the code, rather than text, because my Engl...

wxPython file dialog error: missing "|" in the wildcard string!

I am on Windows7, using Python 2.6 and wxPython 2.8.10.1. I am trying to get this Open File dialog to work but am running into a weird error. This looks like a valid wildcard string to me, but whenever I choose a file and click 'Ok' on the File Dialog, I get this: Traceback (most recent call last): File "D:\Projects\python\wxTest.py",...

python lottery suggestion

I know python offers random module to do some simple lottery. Let say random.shuffle() is a good one. However, I want to build my own simple one. What should I look into? Is there any specific mathematical philosophies behind lottery? Let say, the simplest situation. 100 names and generate 20 names randomly. I don't want to use shuffl...

what is deepcopy's second parameter does,

from copy import* a=[1,2,3,4] c={'a':'aaa'} print c #{'a': 'aaa'} b=deepcopy(a,c) print b print c # print {'a': 'aaa', 10310992: 3, 10310980: 4, 10311016: 1, 11588784: [1, 2, 3, 4, [1, 2, 3, 4]], 11566456: [1, 2, 3, 4], 10311004: 2} why c print that Please try to use the code, rather than text, because my English is not very good, t...

Library for programming Abstract Syntax Trees in Python.

I'm creating a tree to represent a simple language. I'm very familiar with Abstract Syntax Trees, and have worked on frameworks for building and using them in C++. Is there a standard python library for specifying or manipulating arbitrary ASTs? Failing that, is there a tree library which is useful for the same purpose? Note, I am not m...