python

How do I subclass QApplication properly?

I am a newbie with PyQt4 (and QT altogether), and am facing a problem, I have subclassed QApplication (to have global data and functions that really are global to the application): class App(QApplication): def __init__(self): QApplication.__init__(self) self.foo = None def bar(self,x): do_something() ...

How do I write to the apache log files when using mod_wsgi

I have a Django project where I have been logging to a file using the standard library logging module. For a variety of reasons I would like to change it so that it writes to the Apache log files. I've seen quite a bit of discussion of how to do this with mod_python, but not mod_wsgi. How do I do this for a project running under mod_w...

How to use python 2.6 from Visual Basic 2005?

What's the best way to call python scripts from Visual Basic 2005? I've got an application written in visual basic 2005 that needs to call into a library written in python. The library requires python 2.6. I'm using the python C API to access the python library from the visual basic code (private declare function blah lib "python26.dl...

Python datetime TypeError, interger expected

I'm pretty new to Python, so hopefully the problem I'm having has a simple solution. At work we always us either Shell (ksh) or Perl for all of our scripting work. Since python has been shipped with Solaris for some time now, it has (finally) been given the green light as a scripting platform. I've started prototyping some improvements ...

Is there a plugin for vim to auto-import python libraries?

In eclipse you can hit Ctrl+Shift+o to automatically import all the libraries you reference in your code. Is there any similar plugin for vim to have this feature with python? ...

Extract data from large structured file using Java/Python

I have a large text file (~100MB) that need to be parsed to extract information. I would like to find an efficient way of doing it. The file is structured in block: Mon, 01 Jan 2010 01:01:01 Token1 = ValueXYZ Token2 = ValueABC Token3 = ValuePQR ... TokenX = Value123 Mon, 01 Jan 2010 01:02:01 Token1 = ValueXYZ Token2 = Val...

How to apply a function to every element in a list using Linq in C# like the method reduce() in python?

How to apply a function to every element in a list using Linq in C# like the method reduce() in python? ...

Accurate signal delay calculation in Python

Hi, I'm trying to calculate the lag between two signals in Python using cross correlation. The two signals are almost identical except for a very small timelag. I've tried numpy.correlate and scipy.convolve (alot faster) and both works relatively well but gives a small error. I'm starting to suspect that the error is the result of Pytho...

Google app engine, multiple languages

Hi, i'm working on on a project with DJango but i'm also thinking about going the Jython route. By doing so...since i'll be using the java instance instead of cpython wouldn't I be able to use java, scala, ruby and other other languages that run on top of the jvm if need be? ...

Computing number of sub-queries in Google AppEngine

How can I determine how many sub-queries are required for a single top-level query on app engine (python)? I am playing around with the IN operator, and I am curious if there is any way to be notified if I over-step my 30 sub-query limit. ...

wxPython validators not working as expected

I've written a dialog in wxPtyhon with two comboboxes to which I've attached a custom validator, the purpose being to insure that, if a value is typed, it is an numeric string. Problem is, the validators aren't being invoked. What am I doing wrong? import wx # my custom validator class class NumericObjectValidator(wx.Valid...

(Usage of Class Variables) Pythonic - or nasty habit learnt from java ?

Hello Pythoneers: the following code is only a mock up of what I'm trying to do, but it should illustrate my question. I would like to know if this is dirty trick I picked up from Java programming, or a valid and Pythonic way of doing things: basically I'm creating a load of instances, but I need to track 'static' data of all the instan...

Monitor Synchronization: Implementing multiple condition variables

I am implementing monitor synchronization. I was wondering how does implementing multiple condition variables works. So a condition variable has method wait() which puts it on the wait queue for a specific lock tied to this condition variable. So if I have multiple condition variables, do each wait call create its own separate wait queue...

remove duplicate list elements

I want to remove the duplicate elements in a list only when one element is repeated many times, like this: li = ['Human','Human','Human'] => li = ['Human'] but not when there are two or more different elements: li = ['Human','Monkey','Human', 'Human'] Many thanks in advance. ...

twisted: no exception trace if error from a callback

Consider the following code: df = defer.Deferred() def hah(_): raise ValueError("4") df.addCallback(hah) df.callback(hah) When it runs, that exception just gets eaten. Where did it go? How can I get it to be displayed? Doing defer.setDebugging(True) has no effect. I ask this because other times, I get a printout saying "Unhandled err...

INVALID SYNTAX ERROR for 'else' statement in python

I am trying to write a quicksort program in python, however I'm getting an invalid syntax error at else statement in the second last line below: import random n=int(raw_input("Enter the size of the list: ")) # size of the list intlist = [0]*n for num in range(n): intlist[num]=random.randint(0,10*n) pivot=random.choice(intlist) lis...

How to write a python program to calculate pi

The German mathematician Gottfried Leibniz developed the following method to approximate the value of pi: pi/4 = 1- 1/3 + 1/5 - 1/7 + 1/9 - 1/11 ... Write a program that allows the user to specify the number of iterations used in this approximation and that displays the resulting value for pi. ...

Trying to format Google App Engine DateTimeProperty for template

I'm using the Tornado framework (Python) on GAE. I'm still kind of new to the whole MVC concept and GAE... and having a dang of a time trying to figure out how to do this. I have a table (model) Post with the fields user, text, creation_date. I pull all the posts in the code and then send it to the template. I want to format the crea...

"Boolean" operations in Python (ie: the and/or operators)

This method searches for the first group of word characters (ie: [a-zA-Z0-9_]), returning the first matched group or None in case of failure. def test(str): m = re.search(r'(\w+)', str) if m: return m.group(1) return None The same function can be rewritten as: def test2(str): m = re.search(r'(\w+)', str) r...

using python.ctypes with cygwin

I want to use python's (2.6.5) ctypes with cygwin, but I don't know how to load a dll. I tried various variants like >>> form ctypes import * >>> cdll.LoadLibrary("/lib/libcairo.dll.a") Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.6/ctypes/__init__.py", line 431, in LoadLibrary r...