python

How do I set up rpy2?

Hi I just download rpy2 and Python 2.6. When I try to run some of example code I found on the internet, I got this error. Can anyone explain why this is happening and how can I fix it? Thanks. import rpy2.robjects as RO Traceback (most recent call last): File "<pyshell#0>", line 1, in <module> import rpy2.robjects as RO File "C...

Having some trouble creating my Model in Pylons

I've been reading the Pylons Book and, having got to the part about Models, realise it's out of date. So I then switched over to the official Pylons documentation for creating Models in Pylons 1.0 - http://pylonshq.com/docs/en/1.0/tutorials/quickwiki_tutorial/ I've followed what they've got and it's still failing. ./blog/model/init.py ...

method factories which take class attributes as parameters

I'm finding it useful to create "method factory functions" that wrap a parametrized object attribute in some logic. For example: """Fishing for answers. >>> one().number_fisher() 'one fish' >>> one().colour_fisher() 'red fish' >>> two().number_fisher() 'two fish' >>> two().colour_fisher() 'blue fish' """ class one(object): def n...

How I can develop a screen-capture tool in Python

Hello, I'm learning Python now and I want to develop a screen capture tool in Python.How I can do this work? ...

how to check the neighbouring states in python

The newPos gives me the position of pacman agent (like (3,5) ). newPos = successorGameState.getPacmanPosition() The oldfood gives me the remaining food available for pacman in the form of grid. We can access the grid via list like if we want to know if food is available at (3,4) then we do oldFood = currentGameState.getFood() i...

how to deepcopy a queue in python.

Hi How to deepcopy a Queue in python? Thanks ...

Memoization Handler

Is it "good practice" to create a class like the one below that can handle the memoization process for you? The benefits of memoization are so great (in some cases, like this one, where it drops from 501003 to 1507 function calls and from 1.409 to 0.006 seconds of CPU time on my computer) that it seems a class like this would be useful. ...

find the neighbouring states around the agent

I need to find the states that are next to my pacman agent. The current state is Tuple(3,5) which is given by numPos. I need to check the position that are around the pacman agent. I want to find the neighbouring states so that i can check it with the ghosts states and if they matches, that means , a ghost is present in the neighbourin...

measuring WLAN using python for S60

Hi, I'm using python for S60. is there a module that enable you to measure WLAN intensity in your area? In the end I want to get a list with all the networks available in the point and their intensity. thanks ...

Relating generically created Django objects with users

I'm new to Python & Django. I want to allow users to create new objects, and for each object to be related to the currently logged in user. So, I thought I'd use the generic create_object method - only I can't work out how best to do this so it's simple and secure. Here's my model: class Book(models.Model): user = models.ForeignKey...

how to change the color of a QGraphicsTextItem

hello i have a scene with a multiple (QGraphicsTextItem)s, and i need to have control over their colors , so how to change a color of a QGraphicsTextItem ? is it possible anyway? i've been trying for 3 days until now . please help thanks in advance ...

gsm location in python

Hi, I have this script file in python running on S60: import location def current_location(): gsm_loc = location.gsm_location() print gsm_loc current_location() instead of printing a tuple of mcc, mnc, lac and cellId it prints None. on top of my python shell I see location between the capabilities included. what can be the prob...

Using a tuple as function arguments

For this function I can use tuple elements as arguments: light_blue = .6, .8, .9 gradient.add_color_rgb(0, *light_blue) What if i have to add another argument after the tuple? light_blue = .6, .8, .9 alpha = .5 gradient.add_color_rgba(0, *light_blue, alpha) does not work. What does work is gradient.add_color_rgba(0, *list(light_bl...

How do I efficiently fill a file with null data from python?

I need to create files of arbitrary size that contain no data. The are potentially quite large. While I could just loop through and write a single null character until I've reached the file size, that seems ugly. with open(filename,'wb') as f: # what goes here? What is the efficient, pythonic way to do this? ...

A scalable solution for server side push?

I would like to implement a mechanism which will provide a RESTful API that allows a client to register interest in a subject with a sever, and receive asynchronous notifications from the server after the interest is registered. In enterprise (messaging) architecture, this is known as publish/subscribe 'pattern'. With desktop applicatio...

Python: Detect codecs used in a video container

Hi, I have a couple of video container files which contain audio and video in various codecs. Now I'd like to inspect the container from a Python script to know which codec is used for audio+video. This is on a linux box so I have all the tools available if necessary. I thought that maybe gstreamer could help me here but I was unable t...

LDAP: ldap.SIZELIMIT_EXCEEDED

I am getting an ldap.SIZELIMIT_EXCEEDED error when I run this code: import ldap url = 'ldap://<domain>:389' binddn = 'cn=<username> readonly,cn=users,dc=tnc,dc=org' password = '<password>' conn = ldap.initialize(url) conn.simple_bind_s(binddn,password) base_dn = "ou=People,dc=tnc,dc=org" filter = '(objectClass=*)' attrs = ['sn'] con...

Problem extracting text out of html file using python regex

I'm working on a project that requires me to write some code to pull out some text from a html file in python. <tr> <td>Target binary file name:</td> <td class="right">Doc1.docx</td> </tr> ^Small portion of the html file that I'm interested in. #! /usr/bin/python import os import re if __name__ == '__main__': f = open('./res...

Python and GnuCash: Extract data from GnuCash files

I'm looking for information on how to read GnuCash files using python. I have read about this python-gnucash which provides Python bindings to the GnuCash library, but it takes a lot of work at the moment (e.g. dependencies, headers, etc.). The instructions are tailored for the Linux environment, and a rather old GnuCash version (2.0.x)....

Using ChunkedCorpusReader in nltk

Hello, can someone please post some kind of example for using this to read a file. for example: the fox{{some_tag}} jumped over the((some_other_tag)) lazy dog. the api for it is in: http://nltk.googlecode.com/svn/trunk/doc/api/nltk.corpus.reader.chunked.ChunkedCorpusReader-class.html i can get it to read files and split them over com...