python

Polluting a class's environment

Hi, I have an object that holds lots of ids that are accessed statically. I want to split that up into another object which holds only those ids without the need of making modifications to the already existen code base. Take for example: class _CarType(object): DIESEL_CAR_ENGINE = 0 GAS_CAR_ENGINE = 1 # lots of these ids class ...

writing a custom anaylzer in pylucene/inheritance using jcc?

Hello, I want to write a custom analyzer in pylucene. Usually in java lucene , when you write a analyzer class , your class inherits lucene's Analyzer class. but pylucene uses jcc , the java to c++/python compiler. So how do you let a python class inherit from a java class using jcc ,and especially how do you write a custom pyluc...

Trying to get a solid Python install working on my Mac?

I have Mac OSX 10.5.8 with Xcode installed. I want to avoid MacPorts and want to just get a solid Python install foundation so I can then move on to mess with Django and other things. I want to use Buildout with my Python applications. I have installed binary Python 2.6.4 from the official site and installed this. Following other advice...

assertRaises just catches base exception

I'm running into a strange problem when using unittest.assertRaises. When executing the code below I get the following output: E ====================================================================== ERROR: testAssertRaises (__main__.Test) ---------------------------------------------------------------------- Traceback (most recent call...

attribute assignment order in class definition

Hi my problem is that: I want to define a class in this way: class List(Base): hp = Column(int,...) name = Column(str,...) This class represents a list, I can define/modify/code the Base and the Column class. There's a way to know the order in which I defined the attributes hp/names? For example I want to define a method that...

Suppressing Cherrypy's output when runing unit tests using Nose.

Hello, I'm using cherrypy to implement a web server and I use nose to run my unit tests. However, there is a lot of debug noise that nose catches and prints to stdout, even when I use the --nologcapture, particularly cherrypy's logging messages. That makes the testing output quite difficult to read. I've thought that: def setUp(self):...

How to move into multiple directories Python

Hello, I am creating several directories a day. After seven days I am going to drop a sandbox in these directories and delete them. I use a time stamp to name them. I have got some code below to show you what I have got. today = datetime.date.today() # Today's date Binary todaystr = datetime.date.today().isoformat() # Todays date as a ...

Django, create_user giving error, manually creating user gives different error

Working with Django 1.1 on Python 2.6.4, trying to execute the following: user = User.objects.create_user(username, email, password) The three values are from form.cleaned_data, and have already been validated. i get this error: 'dict' object has no attribute 'strip' Traceback: File "/usr/lib/pymodules/python2.6/django/core/handlers/...

Commands for breakpoints in a .pdbrc file

Hi all, I'd like to save the commands for a breakpoint in a .pdbrc, something like: b 81 commands 1 pp foo.attr1 pp foo.attr2 end b 108 commands 2 pp bar.attr1 pp bar.attr2 end This would automate setting the environment for the debugging session. However, this does not work with 'python -m pdb script.py', because at the ...

Is it possible to create an end-user facing site using Django admin alone?

I'm very new to Django, having never developed on it. I'm trying to develop a site which has functionality exposed only to authenticated users (typical enterprise thing: for this discussion, let's say it's a private blogging platform). The functionality I'm looking for is: Users can create a new blog. each user can belong to multip...

Compiling and installing pyactivemq on osx

I'm having a hardtime trying to install pyactivemq (link) on my osx leopard. Following a tutorial (in portuguese) on compiling it ends up ok, but when I run the tests i receive only a crypt message: "Fatal Python error: Interpreter not initialized (version mismatch?)" There is not much information on the web about using pyactivemq on ...

Got Django and Buildout working, but what about PIL and Postgres?

Hello. I'm on Mac OSX 10.5.8. I have followed Jacob Kaplan-Moss's article on setting up Django with Buildout: http://jacobian.org/writing/django-apps-with-buildout/ Finally, I have got this Buildout to work! ...but I'm now needing PIL and Postgres for a complete isolated Django development area. I've tried to modify my buildout.cfg with...

Is it possible to use KHTMLPart completely from console?

I'm using the KHTMLPart component from the PyKDE (in Python) library to download some webpages in the background and return sizes of certain elements in pixels. I don't really need any visual output from this script, indeed I will probably run it on a server without X installed. The problem is that when I tell my application to run conso...

Django: How should I store a money value?

I'm running into a paradigm problem here. I don't know whether I should store money as a Decimal(), or if I should store it as a string and convert it to a decimal myself. My reasoning is this: PayPal requires 2 decimal places, so if I have a product that is 49 dollars even, PayPal wants to see 49.00 come across the wire. Django's Decim...

Difficulty getting flup fcgi script to work

I'm building a site for a client using django. It's been hosted on shared hosting and mod_wsgi can't be used. In the old year, I got it working using fcgi, but when I got back, it was broken. I have replaced the fcgi script with a simple hello world script: #!/usr/bin/python def myapp(environ, start_response): start_response('200 O...

Python: How do you format a string % number with str.format()

How can I format a string like this "%01.2f" % pr"%01.2f" % some_number but using the str.format() style? I'm used to this: '{0} {1}'.format(somevalue1, somevalue2) Is there a way to use that function style vs the old % style, and still achieve this decimal formatting? ...

Null pattern in Python underused?

Every now and then I come across code like this: foo = Foo() ... if foo.bar is not None and foo.bar.baz == 42: shiny_happy(...) Which seems, well, unpythonic, to me. In Objective-C, you can send messages to nil and get nil as the answer. I've always thought that's quite handy. Of course it is possible to implement a Null pattern i...

zooming pictures with wx.image

hello . im doing a software that paints over images and save them ( for commenting propose ) . i used the code below to display image to be drown upon. the problem is: how can i zoom in and out ? . or should i use another way to display that image ? bitmap=wx.bitmap(path,wx.BITMAP_TYPE_ANY) buffer =wx.EmptyBitmap(500,500,32) dc = wx....

PHP Bayesian Classifier

Hi All, I'm looking for a Naive Bayesian Classifier for PHP, ideally something equivalent to the Reverend Bayes version written in Python. Does anyone know of such a library? Basically I need to be able to train it with a set of labels and words i.e. GOOD = okay, happy, fun; BAD = wrong, rubbish, awful etc and then pass it a string val...

Force python mechanize/urllib2 to only use A requests?

Here is a related question but I could not figure out how to apply the answer to mechanize/urllib2: http://stackoverflow.com/questions/1540749/how-to-force-python-httplib-library-to-use-only-a-requests Basically, given this simple code: #!/usr/bin/python import urllib2 print urllib2.urlopen('http://python.org/').read(100) This result...