python

How to get the contents of a field instead of `<bound method...` in a CSV output with Python (pytwist)

The snippet below is generating "weird" output: for s in servers: vo = ss.getServerVO(s) values = [] for f in voFields: attribValue = getattr(vo, f) values.append(attribValue) customValues = ss.getCustomFields(s) for f in customFields: values.append(customValues[f]) # Convert all values to...

Python list entries are overridden by last appended entry

I've got this code: def __parse(self): for line in self.lines: r = Record(line) self.records[len(self.records):] = [r] print self.records[len(self.records)-1].getValue() # Works fine! print self.record[0].getValue() # Gives the same as print self.record[1].getValue() # as # ... and so on ....

Logging in worker threads spawned from a pylons application does not seem to work

I have a pylons application where, under certain cirumstances I want to spawn multiple worker threads to process items in a queue. Right now we aren't making use of a ThreadPool (would be ideal, but we'll add that in later). The main problem is that the worker threads logging does not get written to the log files. When I run the code ou...

Python string decoding issue

I am trying to parse a CSV file containing some data, mostly numeral but with some strings - which I do not know their encoding, but I do know they are in Hebrew. Eventually I need to know the encoding so I can unicode the strings, print them, and perhaps throw them into a database later on. I tried using Chardet, which claims the stri...

python xmpp server libray

I know there are several libraries to connect to xmpp servers, but is there an xmpp server library somewhere written in python? ...

python: inheriting or composition

Let's say that I have class, that uses some functionality of dict. I used to composite a dict object inside and provide some access from the outside, but recently thought about simply inheriting dict and adding some attributes and methods that I might require. Is it a good way to go, or should I stick to composition? ...

Python Decimals format

WHat is a good way to format a python decimal like this way? 1.00 --> '1' 1.20 --> '1.2' 1.23 --> '1.23' 1.234 --> '1.23' 1.2345 --> '1.23' ...

GWT Request Builder problem (same site policy issue?)

I am trying out GWT in this 'configuration': 1) I have written a server backend in python which will produce json output (running at localhot:8094) 2) I have written a very simple GWT app that will use RequestBuilder to set GET to the python server (in development mode of the GWT eclipse plugin, it is accessible via http://127.0.0.1:88...

PSP class import + MySQL connect

Ok so im trying to import a class i made which connects to a MySQL database the class code is shown below: class connection def__init__( self ): self.cnx = MySQLdb.connect(user='xxx',host='xxx',passwd='xxx',db='xxx') All of the parameters for the mysql connection are correct and file containg the class is in the same direc...

Compressed xml on soappy

I'm developing an application that uses webservices in python, both sides (server and client) are developed in Python and uses SOAPpy for the webservices, but, you know, the xml is too verbose, I want to compress it, but as far as I have searched in google I can't find something helpful. ...

Python: wingIDE syntax highlighting customization

Hello, I'm using the free version of wingIDE. I am trying to customize individual syntax highlighting colors (comments, strings, constants, normal text, etc). I see the generic color changes for 'background,selected text", etc, but nothing that lets me get down to specifics. Is this a limitation of the free version or is the option hidd...

Collaborative Filtering: Non-Personalized item-to-item similarity

I'm trying to compute item-to-item similarity along the lines of Amazon's "Customers who viewed/purchased X have also viewed/purchased Y and Z". All of the examples and references I've seen are for either computing item similarity for ranked items, for finding user-user similarity, or for finding recommended items based on the current u...

Most efficent way to create all possible combinations of four lists in Python?

I have four different lists. headers, descriptions, short_descriptions and misc. I want to combine these into all the possible ways to print out: header\n description\n short_description\n misc like if i had (i'm skipping short_description and misc in this example for obvious reasons) headers = ['Hello there', 'Hi there!'] descriptio...

Regex + Python to remove specific trailing and ending characters from value in tab delimited file

It's been years (and years) since I've done any regex, so turning to experts on here since it's likely a trivial exercise :) I have a tab delimited file and on each line I have a certain fields that have values such as: foo bar b"foo's bar" b'bar foo' b'carbar' (A complete line in the file might be something like: 123\t b'bar foo'...

only parse a specific subtree of an XML file

I have a massive XML file. However, I'm only interested in a single small subtree of this massive tree. I want to parse this subtree, but I don't want to waste time parsing the entire massive tree when I'm going to only be using a small part of it. Ideally, I'd want to scan through the file until I find the start of this subtree, parse...

Is there a way to transparently perform validation on SQLAlchemy objects?

Is there a way to perform validation on an object after (or as) the properties are set but before the session is committed? For instance, I have a domain model Device that has a mac property. I would like to ensure that the mac property contains a valid and sanitized mac value before it is added to or updated in the database. It looks ...

How do I disable and then re-enable a warning?

I'm writing some unit tests for a Python library and would like certain warnings to be raised as exceptions, which I can easily do with the simplefilter function. However, for one test I'd like to disable the warning, run the test, then re-enable the warning. I'm using Python 2.6, so I'm supposed to be able to do that with the catch_wa...

How to debug Apache XML-RPC client with Python server

I am writing xmlrpc codes to communicate between Apache XML-RPC client and a Python SimpleXMLRPCServer. I have difficulty debugging it, because I can't find a way to see the request XML/response XML. Are there anyway I can see it dump to console or logged in file? ...

How to properly subclass dict and override get/set

I am debugging some code and I want to find out when a particular dictionary is accessed. Well, it's actually a class that subclass dict and implements a couple extra features. Anyway, what I would like to do is subclass dict myself and add override __getitem__ and __setitem__ to produce some debugging output. Right now, I have class Di...

Django serializer for one object

I'm trying to figure out a way to serialize some Django model object to JSON format, something like: j = Job.objects.get(pk=1) ############################################## #a way to get the JSON for that j variable??? ############################################## I don't want want: from django.core import serializers serializers.s...