python

Python 2.6.4 property decorators not working

I've seen many examples online and in this forum of how to create properties in Python with special getters and setters. However, I can't get the special getter and setter methods to execute, nor can I use the @property decorator to transform a property as readonly. I'm using Python 2.6.4 and here is my code. Different methods to use p...

Will shell scripts called from python persist after the python script ends?

As part of an automated test, I have a python script that needs to call two shell scripts that start two different servers that need to interact after the calling script ends. (It's actually a jython script, but I'm not sure that matters at this point.) What can I do to ensure that the servers stay up after the python script ends? At th...

Declare which signals are subscribed to on DBus?

Is there a way to declare which signals are subscribed by a Python application over DBus? In other words, is there a way to advertise through the "Introspectable" interface which signals are subscribed to. I use "D-Feet D-Bus debugger". E.g. Application subscribes to signal X (using the add_signal_receiver method on a bus object). ...

PyQt beginremoverows

Hi all, In the example below: from PyQt4 import QtCore, QtGui class Ui_Dialog(QtGui.QDialog): def __init__(self,parent=None): QtGui.QDialog.__init__(self,parent) self.setObjectName("Dialog") self.resize(600, 500) self.model = QtGui.QDirModel() self.tree = QtGui.QTreeView() self.tree...

Cross-platform desktop notifier in Python

I am looking for Growl-like, Windows balloon-tip-like notifications library in Python. Imagine writing code like: >>> import desktopnotifier as dn >>> dn.notify('Title', 'Long description goes here') .. and that would notify with corresponding tooltips on Mac, Windows and Linux. Does such a library exist? If not, how would I go about ...

Is CherryPy a robust webserver (ie, is it reliable under a huge load like Apache)?

I'm wondering because CherryPy is, from my knowledge, built purely in Python, which is obviously slower than C et al. Does this mean that it's only good for dev / testing environments, or could I use it behind NGINX like I use Apache with Fast CGI currently? ...

In Python, How Do I Set an Expiration Date on a User Object in Active Directory?

Setup: I have the user object in hand, via win32com.client.Dispatch('ADsNameSpaces'), in a standard Windows environment, using ActiveState Python of the 2.6 flavor. Apparently, Get() and Put()/SetInfo() methods are the appropriate ways to read from and write to properties of the object. My approach has been to simply adapt examples fro...

Is there a significant overhead by using different versions of sha hashing (hashlib module)

The hashlib Python module provides the following hash algorithms constructors: md5(), sha1(), sha224(), sha256(), sha384(), and sha512(). Assuming I don't want to use md5, is there a big difference in using, say, sha1 instead of sha512? I want to use something like hashlib.shaXXX(hashString).hexdigest(), but as it's just for caching, I'...

Django and VirtualEnv Development/Deployment Best Practices

Hi All, Just curious how people are deploying their Django projects in combination with virtualenv More specifically, how do you keep your production virtualenv's synched correctly with your development machine? I use git for scm but I don't have my virtualenv inside the git repo - should I, or is it best to use the pip freeze and t...

Is there a Python ebXML client?

I am trying to use a remote web service with an ebXML/SOAP interface from my python application and am hitting a wall about how to best accomplish it. So far, what I can find are lots of Java interface bindings but none for Python. Do I have to start my project over in Java? ...

Is it possible to declare a function without arguments but then pass some arguments to that function without raising exception?

In python is it possible to have the above code without raising an exception ? def myfunc(): pass # TypeError myfunc() takes no arguments (1 given) myfunc('param') Usually in php in some circumstances I launch a function without parameters and then retrieve the parameters inside the function. In practice I don't want to declare ...

running clock and triggering

Hi, constantly running a clock and trigger an other function for every 5 seconds. Please give me idea how to do this. Thanks a bunch ...

Python regex - r prefix

Hi Can anyone explain why example 1 below works, when the r prefix is not used? I thought the r prefix must be used whenever escape sequences are used? Example 2 and example 3 demonstrates this.. # example 1 import re print (re.sub('\s+', ' ', 'hello there there')) # prints 'hello there there' - not expected as r prefix is not...

Facebook calling Google App Engine code using GET instead of POST

I've been developing a Facebook app using Google App Engine in Python and the pyfacebook bindings. For weeks everything worked fine but suddenly it stopped. At first I thought it was a code change so I rolled back the entire dev directory to a version I knew worked, but still it failed. It's possible a change I made to the application'...

PySVN error: URL doesn't exist

I got a SVN repository copied onto my computer using svnsync. Now when I try to replay it using PySVN it fails at a specific revision (29762) with the message: pysvn._pysvn_2_6.ClientError: URL 'svn://svn.zope.org/repos/main/ZODB/trunk/src/Persistence' doesn't exist I can checkout or update until the previous revision (29761) ok bu...

How to initialize a dict with keys from a list and empty value in Python?

I'd like to get, from: keys = [1,2,3,4] this: {1: None, 2: None, 3: None} A pythonic way of doing it? This is an ugly one: >>> keys = [1,2,3] >>> dict([(1,2)]) {1: 2} >>> dict(zip(keys, [None]*len(keys))) {1: None, 2: None, 3: None} ...

How to send a xml-rpc request in python?

I was just wondering, how would I be able to send a xml-rpc request in python? I know you can use xmlrpclib, but how do I send out a request in xml to access a function? I would like to see the xml response. So basically I would like to send the following as my request to the server: <?xml version="1.0"?> <methodCall> <methodName>pr...

Any way to show error and backtrace with nosetests --pdb

Is there a way to get nosetests --pdb to automatically show you the error you're trying to debug, as well as a backtrace, BEFORE dumping you into pdb? i.e. instead of: awagner@hesse:/home/awagner/optimization/illumination_search$ nosetests --pdb test_bool_rep (optimization.illumination_search.test_subset_search.SubsetSearchTest) ... ok ...

Python Shell, Logging Commands for Easy Re-Execution

Say I do something like this in a python shell for my Django app: >>>from myapp.models import User >>>user = User.objects.get(pk=5) >>>groups = user.groups.all() What I'd like to do is stash these 3 commands somehow without leaving the shell. The goal being I can quickly restore a similar environment if I restart the shell session lat...

more pythonic way of finding element in list that maximizes a function

OK, I have this simple function that finds the element of the list that maximizes the value of another positive function. def get_max(f, s): # f is a function and s is an iterable best = None best_value = -1 for element in s: this_value = f(element) if this_value > best_value: best = element...