python

Paypal NVP getRecurringPaymentsProfileDetails error 10001

When I call getRecurringPaymentsProfileDetails through the sandbox everything works fine, but when I switched to my live site I started getting 10001 error "Internal Error" Here is what gets returned: {'ack': 'Failure', 'timestamp': '2009-08-25T04:33:23Z', 'l_severitycode0': 'Error', 'l_shortmessage0': 'Internal Error', 'l_longmessage0...

Executing Python Scripts in Android

This link says that Android support Python, Lua and BeanShell Scripts, subsequently for Perl too. If it is so, is it possible for developers to write python scripts and call them in their standard Java based android applications? ...

How to organize a Data Base Access layer?

I am using SqlAlchemy, a python ORM library. And I used to access database directly from business layer directly by calling SqlAlchemy API. But then I found that would cause too much time to run all my test cases and now I think maybe I should create a DB access layer, so I can use mock objects during test instead of access database di...

how to take file like object in a file in python

filename = fileobject.read() i want to transfer/assign the whole data of a object within a file ...

Problem with shelve module?

Using the shelve module has given me some surprising behavior. keys(), iter(), and iteritems() don't return all the entries in the shelf! Here's the code: cache = shelve.open('my.cache') # ... cache[url] = (datetime.datetime.today(), value) later: cache = shelve.open('my.cache') urls = ['accounts_with_transactions.xml', 'targets.xml'...

Django_tagging (v0.3/pre): Configuration issue

I am trying to use the django-tagging in one of my project and run into some errors. I can play with tags in the shell but couldn't assign them from admin interface. What I want to do is add "tag" functionality to a model and add/remove tags from Admin interface. Why is it the "tags" are seen by shell and not by "admin" interface? Wha...

Using sphinx to auto-document a python class, module

Hi, I have installed Sphinx in order to document some python modules and class I'm working on. While the markup language looks very nice, I haven't managed to auto-document a python code. Basically, I have the following python module: SegLib.py And A class called Seg in it. I would like to display the docstrings of the class and mod...

How can I overload the assignment of a class member?

I am writing a Player model class in Python with Django, and I've ran into a small problem with the password member. I'd like the password to be automatically hashed upon assignment, but I can't find anything about overloading the assignment operator or anything. Is there any way I can overload the assignment of password so as to automa...

Append a tuple to a list

Given a tuple (specifically, a functions varargs), I want to prepend a list containing one or more items, then call another function with the result as a list. So far, the best I've come up with is: def fn(*args): l = ['foo', 'bar'] l.extend(args) fn2(l) Which, given Pythons usual terseness when it comes to this sort of th...

file accessing in load_pub_key

Consider the code: fileHandle = open ( 'test8.pem','w' ) fileHandle.write (data) pub_key = M2Crypto.RSA.load_pub_key(open('test8.pem')) Error coming like : File "/usr/lib/python2.4/site-packages/M2Crypto/RSA.py", line 343, in load_pub_key bio = BIO.openfile(file) File "/usr/lib/python2.4/site-packages/M2Crypto/BIO.py", line 186,...

Code refactoring with python decorators?

Hi everyone, I'm actually struggling with some piece of code. I do know that it can be refactored, but I can't find the nice-smart-elegant solution. Here are two functions (much more functions of that kind are in my code): def fooA(param1, param2): if param2 == True: code_chunk_1 fooA_code #uses only param1 if pa...

python extract contents of regex

hello, I want a regular expression to extract the title from a HTML page. Currently I have this: title = re.search('<title>.*</title>', html, re.IGNORECASE).group() if title: title = title.replace('<title>', '').replace('</title>', '') Is there a regular expression that will extract just the contents of so I don't have to remov...

python - problems with regular expression and unicode

Hi I have a problem in python. I try to explain my problem with an example. I have this string: >>> string = 'ÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿÀÁÂÃ' >>> print string ÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿÀÁÂà and i want, for example, replace charachters different from Ñ,Ã,ï with "" i have tried: >>> rePat =...

Having instance-like behaviour in databases

Hey there everyone, Sorry for the bad title, but I have no idea how to put this in short. The Problem is the following: I have a generic item that represents a group, lets call it Car. Now this Car has attributes, that range within certain limits, lets say for example speed is between 0 and 180 for a usual Car. Imagine some more attrib...

Search function with PyGTKsourceview

Hey everyone, I'm writing a small html editor in python mostly for personal use and have integrated a gtksourceview2 object into my Python code. All the mayor functions seem to work more or less, but I'm having trouble getting a search function to work. Obvioiusly the GUI work is already done, but I can't figure out how to somehow build...

Rescale intensities of a PIL Image

What is the simplest/cleanest way to rescale the intensities of a PIL Image? Suppose that I have a 16-bit image from a 12-bit camera, so only the values 0–4095 are in use. I would like to rescale the intensities so that the entire range 0–65535 is used. What is the simplest/cleanest way to do this when the image is represented as PIL'...

Autodocumenting Python using Sphinx

Hi, This is a generalized version of a previous question regarding Sphinx. Is there a way to recursively autodocument modules or packages which contain classes and functions within them? I think it is silly to add the autofunction or automodule directive for each function; There must be a way to automate the process, otherwise I don't...

SHA256 hash in Python 2.4

Hi, Is there a way I can calculate a SHA256 hash in Python 2.4 ? (I emphasize: Python 2.4) I know how to do it in Python 2.5 but unfortunately it's not available on my server and an upgrade will not be made. I have the same problem as the guy in this question, but using Python 2.4. Any help will be greatly appreciated. EDIT: Sorry, I me...

Should I forward arguments as *args & **kwargs?

I have a class that handles command line arguments in my program using python's optparse module. It is also inherited by several classes to create subsets of parameters. To encapsulate the option parsing mechanism I want to reveal only a function add_option to inheriting classes. What this function does is then call optparse.make_option....

Guitar Tablature and Music sheet oriented plugins for wordpress or Drupal

I'm familiar with wordpress and cakePHP; however, I'm building a small community website (hobby) that allows users to post music sheet (pdf/image) or guitar tabs ( text files). These music sheets should be organized by artists and songs. I've already built my own cms, but I'm not looking forward to maintain it as i'm scared I won't have ...