python

Matrix multiplication with Numpy

Hi all, Assume that I have an affinity matrix A and a diagonal matrix D. How can I compute the Laplacian matrix in Python with nympy? L = D^(-1/2) A D^(1/2) Currently, I use L = D**(-1/2) * A * D**(1/2). Is this a right way? Thank you. ...

How to access the request.user in a Piston classmethod

I have a model which contains a ManyToMany to User to keep track of which users have 'favorited' a particular model instance. In my API for this model, when requested by an authenticated user, I'd like to include an 'is_favorite' boolean. However, it seems that any api fields that aren't straight model attributes must be implemebted as ...

How do you create a video file upload form with Django?

I want a user to be able to upload a video from their computer or record it right from their webcam, then fill out other information with a form. I'm writing this app with Django. ...

How to model a m2m relation where the related table can be a city, a region (state) or a country

In Django I have theses models: class Artist(models.Model): name = models.CharField(max_length=128) born_place = models.ForeignKey(???) dead_place = models.ForeignKey(???) live_places = models.ManyToManyField(???) work_places = models.ManyToManyField(???) class Country(models.Model): iso = models.CharField(max_l...

Where to find the win32api module for Python?

I need to download it for Python 2.7, but can't seem to find it... ...

Python permanent assignment variables

I have just started python and came across something kind of strange. The following code assigns a co-ordinate of x=1 and y=2 to the variable test. The test2 variable assigns itself the same value as test and then the [x] value for test2 is changed to the old [x] value minus 1. This works fine, however, when the last part is executed, n...

tcp port 80 redirector in python for windows 7

Hi All, I want to redirect the port 80 traffic to port 3128 for windows 7 , i want to write it in python. I am relatively new to this....could you guys help ..by giving me some pointers regarding from where to start. Thanks. ...

Fetching multiple IMAP messages at once

The examples I've seen about loading emails over IMAP using python do a search and then for each message id in the results, do a query. I want to speed things up by fetching them all at once. ...

How do I use Python 3.1.2 in Textmate?

TextMate 1.5.9 seems to use Python 2.6.1. How do you configure it to use 3.1 instead? I've already installed the 3.1 package and I can use IDLE for interactive sessions, but I want to use TextMate now. I've already seen the post that directs you to define a project variable (TM_PYTHON : interpreter path). I tried this, but when i use Cmd...

py2exe error on MSVCR80.dll

from distutils.core import setup import py2exe,sys,os sys.argv.append('py2exe') try: setup( options = {'py2exe': {'bundle_files': 1}}, console=['my_console_script.py'], zipfile = None, ) except Exception, e: print e outputs: > running py2exe > *** searching for required modules *** > *** parsing results *** > ...

extracting keywords using LDA model

A portion of our project is included here..plagiarism detector.. we are trying to extract common keywords from two input files by comparing each word in file with a database.we created the database and we were able to take word by word from the file and also each row from the table(keyword). now our problem is that the while loop is not...

Flush the console screen with special unicode class workaround for windows console

I"m trying to make a simple text progress bar in windows console and also display utf8 characters. The problem isn't that the unicode characters won't display, they will. It's that in order to make the unicode characters display I used a class to tell sys.stdout what to do. This has interfered with the normal flush() function. How can ...

Getting HTTP GET arguments in Python

I'm trying to run an Icecast stream using a simple Python script to pick a random song from the list of songs on the server. I'm looking to add a voting/request interface, and my host allows use of python to serve webpages through CGI. However, I'm getting hung up on just how to get the GET arguments supplied by the user. I've tried the ...

Safe expression parser in Python

How can I allow users to execute mathematical expressions in a safe way? Do I need to write a full parser? Is there something like ast.literal_eval(), but for expressions? ...

Removing tmp file after return HttpResponse in django

I'm using the following django/python code to stream a file to the browser: wrapper = FileWrapper(file(path)) response = HttpResponse(wrapper, content_type='text/plain') response['Content-Length'] = os.path.getsize(path) return response Is there a way to delete the file after the reponse is returned? Using a callback function or somet...

Qt: best way to add a context menu to the central widget?

I do not understand why in the book Rapid GUI Programming with Python and Qt, a context menu is added to a central widget by calling addActions() on the main window (self), like so (p. 180): self.addActions(self.imageLabel, (editInvertAction, …)) where self is a QMainWindow, and imageLabel is a QLabel set as the centra...

How to call an element in an numpy array?

This is a really simple question, but I didnt find the answer. How to call an element in an numpy array? import numpy as np arr = np.array([[1,2,3,4,5],[6,7,8,9,10]]) print arr(1,1) The code above doesnt work. ...

How to add items to wx.ScrolledPanel?

I want to add dinamically already captured images in hierarchical structure ( one after one). I want to add them to wx.ScrolledPanel ScrolledPanel definition - updated self.hbox = wx.BoxSizer(wx.HORIZONTAL) #self.sizer.Add(self.hbox) self.scroll = scrolled.ScrolledPanel(self, id = -1, pos = wx.DefaultPosition, size = (500, ...

Python install uninstall easy_install

I have two versions of python on my mac: One preinstalled by Apple in /usr/bin One from python.org in /Library/Frameworks/Python.framework/Versions/2.6 easy_install always installs to /usr/bin for some ununderstanable reason So I explicitly now install easy_install in: sh setuptools-0.6c11-py2.6.egg --install-dir=/Library/Framewor...

Checking ogg-Files using Python on OSX and Linux

Hi, I am writing a python module which checks several media and document formats whether the files correct or somehow corrupted/wrong formatted. It returns an error message or - if the file is correct - some information about the file (e.g. framerate, channels, ...) Now I am looking for a python module which I can use to check ogg-File...