python

How to create new list of dicts in python by consolidating dicts in another list?

In Python, I have a list of dicts as follows: orig_list = [{'first_name': u'Jake', 'last_name': u'Sarson', 'display_name': u'AVG', 'team': u'TeamOne', 'value': 7.0}, {'first_name': u'Mike', 'last_name': u'Walsh', 'display_name': u'AVG', 'team': u'TeamTwo', 'value': 12.0}, {'first_name': u'Jake', 'last_name': u'Sarson', 'display_name'...

python compare subsection of 2 strings and see if they match

I have 2 strings e.g. str1 = 'section1.1: this is a heading for section 1' and str2 = 'section1.1: this is a heading for section 1.1' I want to compare the text which comes after 'section1.1:' and return whether it is the same or not. In the example it would return false as the first says section 1 and the second says section 1...

Using Drupal 7 or developing a new system: What's better for a website relaunch with a community of 15.000 users?

Hi, I have to make a decision for our (eXma german) community webpage. We will relauching it with a new system. There are two sites: The first is to develop a whole new system on e.g. Django and Python. The second is to use the new Drupal 7. Personally I have a lot more experiences with Drupal 6 and now since I'm testing Drupal 7 ...

How to safely open/close files in python 2.4

I'm currently writing a small script for use on one of our servers using Python. The server only has Python 2.4.4 installed. I didn't start using Python until 2.5 was out, so I'm used to the form: with open('file.txt', 'r') as f: # do stuff with f However, there is no with statement before 2.5, and I'm having trouble finding ex...

Optimizing Python Code for Database Access

Hi, I am building an application with objects which have their data stored in mysql tables (across multiple tables). When I need to work with the object (retrieve object attributes / change the attributes) I am querying the sql database using mysqldb (select / update). However, since the application is quite computation intensive, the e...

Python - signal.alarm function

Dear All, I'm trying to build a python timeout exception that runs in milliseconds. The python signal.alarm function has a 1 second resolution. How would one get an equivalent function that requests a SIGALRM signal to a given process in, say milliseconds, as opposed to seconds? I've found no simple solutions as of yet. Thanks in ad...

Scala or Python to Build a Comet server to support a PHP application?

Hi, I have a currently running PHP application that I want to add real-time feed (Google search latest result feeds), I have an implementation in PHP that does the following: An AJAX request to the server. The PHP responds. After 15000ms (15 seconds) using setTimeout(), we repeat the steps. I knew this have very much overhead on the...

Why I can not make python3.1 working with posgresql 9.0

I'm trying to use py-postgresql, since it is only API I found which suppose to work with python3. Any suggestions or help is most welcome. Below is the error popping up: >>> import postgresql.driver Traceback (most recent call last): File "<stdin>", line 1, in <module> File "postgresql/driver/__init__.py", line 9, in <module> fr...

Python average tabular data help

Ok I have the following working program. It opens of a file of data in columns that is too large for excel and finds the average value for each column: Sample data is: Joe Sam Bob 1 2 3 2 1 3 And it returns Joe Sam Bob 1.5 1.5 3 This is good. The problem is some columns have NA as a value. I want to skip this NA and calcul...

Python: using Self and adding methods to an object on the fly

Here's my idea: Start with a simple object: class dynamicObject(object): pass And to be able to add pre written methods to it on the fly: def someMethod(self): pass So that I can do this: someObject = dyncamicObject() someObject._someMethod = someMethod someObject._someMethod() Problem is, it wants me to specify the self...

PyQT QtGui.QTableWidgetItem

I have a QtGui.QTableWidgetItem that I added to a table by the createRow function below: def createRow(self, listA): rowNum = self.table.rowCount() self.table.insertRow(rowNum) i = 0 for val in listA: self.table.setItem(rowNum, i, QtGui.QTableWidgetItem(val)) i += 1 Now I have a thread that will update ...

Authentication on App Engine / Python / Django non-rel over JSON

I'm building a site on Google App Engine, running python and Django non-rel. Everything is working great for HTML and posting/reading data. But as I'm moving forward I'd like to do many of the updates with AJAX, and eventually also over mobile devices like Android and iPhone. My pages use django non-rel and my login/logout authenticatio...

Python os.walk + follow symlinks

How do I get this piece to follow symlinks in python 2.6? def load_recursive(self, path): for subdir, dirs, files in os.walk(path): for file in files: if file.endswith('.xml'): file_path = os.path.join(subdir, file) try: do_stuff(file_path) exce...

Ambiguous tab completion not working in iPython on Windows

I am running IPython on Windows 7 x64 with pyreadline installed. If I start a new session and type: import numpy nu<TAB> Then nu autocompletes to numpy. However, if I start a new session and try this: import numpy n<TAB> Then nothing happens. I would expect it to cycle through all of the possible completions. I'm currently usin...

pythonic way to wrap xmlrpclib calls in similar multicalls

I'm writing a class that interfaces to a MoinMoin wiki via xmlrpc (simplified code follows): class MoinMoin(object): token = None def __init__(self, url, username=None, password=None): self.wiki = xmlrpclib.ServerProxy(url + '/?action=xmlrpc2') if username and password: self.token = self.wiki.getAut...

Python multiprocessing Pool.map is calling aquire?

I have a numpy.array of 640x480 images, each of which is 630 images long. The total array is thus 630x480x640. I want to generate an average image, as well as compute the standard deviation for each pixel across all 630 images. This is easily accomplished by avg_image = numpy.mean(img_array, axis=0) std_image = numpy.std(img_array, axi...

python 3.1 - DictType not part of types module?

This is what I found in my install of Python 3.1 on Windows. Where can I find other types, specifically DictType and StringTypes? >>> print('\n'.join(dir(types))) BuiltinFunctionType BuiltinMethodType CodeType FrameType FunctionType GeneratorType GetSetDescriptorType LambdaType MemberDescriptorType MethodType ModuleType TracebackType _...

Python unittest - invoke unittest.main() with a custom TestSuite

I'm making unittests with python. I am not using any automatical test discovery. I am assembling TestCases into a TestSuite manually. I can run these tests with unittest.TextTestRunner().run(suite), I would like to run them with unittest.main() so that I can use command line options (like -v/--failfast). The documentation says that unit...

How to reload modules in django shell?

I am working with Django and use Django shell all the time. The annoying part is that while the Django server reloads on code changes, the shell does not, so every time I make a change to a method I am testing, I need to quit the shell and restart it, re-import all the modules I need, reinitialize all the variables I need etc. While iPyt...

Google App Engine python Filter "property of property"

Having these models on google app engine: class Choice(db.Model): poll = db.ReferenceProperty(Poll, collection_name = 'choices' ) text = db.StringProperty() class Vote(db.Model): choice = db.ReferenceProperty(Choice, collection_name = 'votes' ) ip = db.StringProperty() date = db.DateTimeProperty(auto_now=1) How do...