python

about python scripting

I have this code class HNCS (ThreadingTCPServer): def verify_request(self, request, client_address): for key in connections: if connections[key].client_address[0] == client_address[0]: if client_address[0] != '127.0.0.1': return False return True def welcome...

Can ElementTree be told to preserve the order of attributes?

I've written a fairly simple filter in python using ElementTree to munge the contexts of some xml files. And it works, more or less. But it reorders the attributes of various tags, and I'd like it to not do that. Does anyone know a switch I can throw to make it keep them in specified order? Context for this I'm working with and on a...

Location of global libraries for Python on Mac ?

Hi, I'm fighting with installation SIP for Python on Mac OS X. Finally after compilation and installation when I run console form folder of SIP (locally) I can import sipconfig, but when I`m in other folder I cant - there is no module called sipconfig. My question is - Where is folder to which I have to copy modules if I want to have th...

A simple Python deployment problem - a whole world of pain

We have several Python 2.6 applications running on Linux. Some of them are Pylons web applications, others are simply long-running processes that we run from the command line using nohup. We're also using virtualenv, both in development and in production. What is the best way to deploy these applications to a production server? In devel...

Python Profiling In Windows, How do you ignore Builtin Functions

I have not been capable of finding this anywhere online. I was looking to find out using a profiler how to better optimize my code, and when sorting by which functions use up the most time cumulatively, things like str(), print, and other similar widely used functions eat up much of the profile. What is the best way to profile a python ...

Is TDD broken in Python?

Hi! Assume we have a class UserService with attribute current_user. Suppose it is used in AppService class. We have AppService covered with tests. In test setup we stub out current_user with some mock value: UserService.current_user = 'TestUser' Assume we decide to rename current_user to active_user. We rename it in UserService but ...

Best way to parse XMPP-like XML streams?

I am working on a server application which receives data over a TCP socket in an XMPP-like XML format, i.e. every child of the <root> element essentially represents one separate request (stanza). The connection is closed as soon as </root> is received. I do know that I must use a stream parser like SAX, somehow. Though, for convenience, ...

Can't run os.system command in Django?

We have a Django app running on apache server (mod_python) on a windows machine which needs to call some r scripts. To do so it would be easiest to call r through os.system, however when django gets to the os.system command it freezes up. I've also tried subprocess with the same result. We have a possibly related problem in that Djang...

Python performance improvement request for winkler

I'm a python n00b and I'd like some suggestions on how to improve the algorithm to improve the performance of this method to compute the Jaro-Winkler distance of two names. def winklerCompareP(str1, str2): """Return approximate string comparator measure (between 0.0 and 1.0) USAGE: score = winkler(str1, str2) ARGUMENTS: str1 The ...

Url for the current page from a Mako template in Pylons

I need to know the full url for the current page from within a Mako template file in Pylons. The url will be using in an iframe contained within the page so it needs to be known when the page is being generated rather than after the page hits the server or from the environment. (Not sure if I am communicating that last bit properly) ...

Unable to open images with Python's Image.open()

My code reads: import Image def generateThumbnail(self, width, height): """ Generates thumbnails for an image """ im = Image.open(self._file) When I call this function, I get an error: ⇝ AttributeError: type object 'Image' has no attribute 'open' However in the console: import Image im = Image.open('test.jpg') I ...

What Python based Dashboard options exist?

I want to create a Dashboard on each server to show it's health and the results of some daily processing. I plan to hook up shell scripts and Python programs to collect the data. Instead of writing a web-based interface, I thought it would be good to use a python based web dashboard that could render the results in various business user...

Python match and return string in between

I have stringA = "xxxxxxFoundAaaaaaaaaaaaaaaFoundBxxxxxxx" stringB = "FoundA" stringC = "FoundB" How do I do a regular expression in python in order to return aaaaaaaaaaaaaa? Please help. Thanks in advance. ...

Calculating time until 1st or 15th of the month in python

I'm trying to write a little budget program in python. This is my first program I'm writing to learn python. The first step is to calculate how many days until either the 1st or 15th (paydays) depending on today's date. Can someone help me out a little? ...

dropEvent not being called on custom view in PyQt4?

I'm trying to create a custom QTableView that will respond to drag and drop actions. So far, I have something like the following: from PyQt4.QtCore import * from PyQt4.QtGui import * class FooTableView(QTableView): def __init__(self, parent = None): QTableView.__init__(self, parent) self.setAcceptDrops(True) d...

Problem comparing keys in Appengine/Python

I'm trying to create a relationship between "tables" with Appengine/Python. Imagine I have a "table" for items, and a table for colors. I save the color of an item by saving the color key as an atribute of the item. That's working well, but this particular piece of code is not working: <select id="colorKey" name="colorKey"> {% for c...

Mako "Missing parentheses in %def"

In trying to add a cached section to a Mako template, I get the error listed in the above question. Adding () to the end gets rid of the error, but I see no content on my page. Any help is appreciated! <%def name="test" cached="True" cache_timeout="60" cache_type="file"> Test /%def> ...

How to embed the Python interpreter in a Qt app?

Is there a straightforward way to embed the Python interpreter in a Qt application? I am hoping for a cross-platform solution if possible. ...

Python: How to round 123 to 100 instead of 100.0?

round(123,-2) 100.0 How to round it to 100 instead of 100.0? ...

How do I use a ListProperty(users.user) in a djangoforms.ModelForm on Google AppEngine?

I have been looking around a bit for info on how to do this. Essentially I have a Model: class SharableUserAsset(db.Model): name = StringProperty() users = ListProperty(users.User) My questions are: What is the best way to associate users to this value where they are not authenticated, visa vi invite from contacts list etc.? Is ...