python

Correct approach to validate attributes of an instance of class

Having a simple Python class like this: class Spam(object): __init__(self, description, value): self.description = description self.value = value Which is the correct approach to check these constraints: "description cannot be empty" "value must be greater than zero" Should i: 1. validate data before creating...

Spotting similarities and patterns within a string - Python

Hi folks, this is the use case I'm trying to figure this out for. I have a list of spam subscriptions to a service and they are killing conversion rate and other usability studies. The emails inserted look like the following: [email protected] [email protected] [email protected] ro...

Is there a wxPython equivalent of datetime.combine?

The python datetime.datetime object has the combine method. Is there an equivalent for wx.DateTime objects? ...

Django + Apache wsgi = paths problem

Hello. I have this view which generates interface language options menu def lang_menu(request,language): lang_choices = [] import os.path for lang in settings.LANGUAGES: if os.path.isfile("gui/%s.py" % lang) or os.path.isfile("gui/%s.pyc" % lang): langimport = "from gui.%s import menu" % lang ...

python check value not in unicode list

Hi, I have a list and a value and want to check if the value is not in the list. list = [u'first record', u'second record'] value = 'first record' if value not in list: do something however this is not working and I think it has something to do with the list values having a u at the start, how can I fix this? And before someone...

Generating unique number sequence for use as entity key for app engine datastore

Has anyone got any example code for creating a unique number sequence to be used as keys for an entity in a Google app engine datastore? Would like to use sequential order numbers as the key. ...

Creating a document tree before or after adding the subelements.

Hello everyone. I am using lxml and Python for writing XML files. I was wondering what is the accepted practice: creating a document tree first and then adding the sub elements OR adding the sub elements and creating the tree later? I know this hardly makes any difference as to the output, but I was interested in knowing what is the acc...

Simple XML over http web service

I have a simple html service, developed in django. You enter your name - it posts this, and returns a value (male/female). I need to ofer this as a web service. I have no idea where to start. I want to accept a xml request, and provide an xml response - thats it. Can anyone give ma any pointers - Googling it is difficult when you don...

Python to Java translation

Hello, i get quite short code of algorithm in python, but i need to translate it to Java. I didnt find any program to do that, so i will really appreciate to help translating it. I learned python a very little to know the idea how algorithm work. The biggest problem is because in python all is object and some things are made really ve...

Does Google appengine cache external requests?

I have a very simple application running on appengine that requests a web page every five minutes and parses for a specific piece of data. Everything works fine except that the response I get back from the external request (using urllib2) doesn't reflect the latest changes to the page. Sometimes it takes a few minutes to get the latest,...

delete all records except the id I have in a python list

Hi all, I want to delete all records in a mysql db except the record id's I have in a list. The length of that list can vary and could easily contain 2000+ id's, ... Currently I convert my list to a string so it fits in something like this: cursor.execute("""delete from table where id not in (%s)""",(list)) Which doesn't feel right an...

Good automated system testing framework in python

I am looking for good End to End testing framework under python, where the tests can be written in python and managed in a comfortable way. I know there are many unit testing frameworks, but I am looking for bigger scope, something like test director with support for reports etc,where a whole system is under test. ...

python logparse search specific text

hi, I am using this function in my code to return the strings i want from reading the log file, I want to grep the "exim" process and return the results, but running the code gives no error, but the output is limited to three lines, how can i just get the output only related to exim process.. #output: {'date': '13', 'process': 'sys...

How do I rectify a "Cannot Initialise OLE error"?

I was trying to embed video from a webcam into a wxPython app. This error occurs on trying to import a submodule of pyvision (from pyvision.types.Video import Webcam) ...

django url matching

can anyone see why this wouldn't be working. Fairly new to django so any help would be much appreciated actual url: http://127.0.0.1:8000/2010/may/12/my-second-blog-post/ urls.py: (r'(?P<year>d{4})/(?P<month>[a-z]{3})/(?P<day>w{1,2})/(?P<slug>[-w]+)/$', 'object_detail', dict(info_dict, slug_field='slug',template_name='blog/detail.html...

Angles between two n-dimensional vectors in Python

In need to determine the angle(s) between two n-dimensional vectors in Python. For example, the input can be two lists like the following: [1,2,3,4] and [6,7,8,9]. Can anybody help me? Thanks in advance! ...

Application with both console and gui mode

Hi, I have a python console app. Like most python console apps it uses the OptionParser module to take arguments. I've now developed a GUI for my app using wxPython and i'd like to integrate the two. I'd like my app to be run both from the console and from the OS's UI. When it is invoked from the console it runs as a console app and whe...

sorl-thumbnail unit tests fail by 1 pixel (!)

Hi I'm using sorl-thumbnail in a Django 1.2 (currently 1.2 RC) project and getting a surprising failure of four of sorl's built-in unit tests. Essentially, the resized images are all 1px shorter than the unit tests expect them to be. See below for details I'm developing on OSX 10.5.8 (not Snow Leopard) with Python 2.5.1 (r251:54863, F...

python create object and add attributes to it

Hi, I want to create a dynamic object (inside another object) in python and then add attributes to it. I tried: obj = someobject obj.a = object() setattr(obj.a, 'somefield', 'somevalue') but this didn't work. Any ideas? edit: I am setting the attributes from a for loop which loops through a list of values. e.g. params = ['attr1'...

sorting arrays in numpy by column

How can I sort an array in numpy by the nth column? e.g. a = array([[1,2,3],[4,5,6],[0,0,1]]) I'd like to sort by the second column, such that I get back: array([[0,0,1],[1,2,3],[4,5,6]]) thanks. ...