python

How to execute a file within the python interpreter?

Hi, I'm trying to execute a file with python commands from within the interpreter. EDIT: I'm trying to use variables and settings from that file, not to invoke a separate process. ...

MySQLdb through proxy

I'm using the above mentioned Python lib to connect to a MySQL server. So far I've worked locally and all worked fine, until i realized I'll have to use my program in a network where all access goes through a proxy. Does anyone now how I can set the connections managed by that lib to use a proxy? Alternatively: do you know of another Py...

Detect if X11 is available (python)

Firstly, what is the best/simplest way to detect if X11 is running and available for a python script. parent process? session leader? X environment variables? other? Secondly, I would like to have a utility (python script) to present a gui if available, otherwise use a command line backed tool. Off the top of my head I thought of th...

Is python a stable platform for facebook development?

I'm trying to build my first facebook app, and it seems that the python facebook (pyfacebook) wrapper is really out of date, and the most relevant functions, like stream functions, are not implemented. Are there any mature python frontends for facebook? If not, what's the best language for facebook development? ...

Conditional Django Middleware (or how to exclude the Admin System)

Hi all, I want to use some middleware I wrote across the whole of my site (large # of pages, so I chose not to use decorators as I wanted to use the code for all pages). Only issue is that I don't want to use the middleware for the admin code, and it seems to be active on them. Is there any way I can configure the settings.py or urls.p...

Can I avoid handling a file twice if I need the number of lines and I need to append to the file?

I am writing a file to disk in stages. As I write it I need to know the line numbers that I am writing to use to build an index. The file now has 12 million lines so I need to build the index on the fly. I am doing this in four steps, with four groupings of the value that I am indexing on. Based on some examples I found elsewhere on ...

Is there a Python interface to the Apache scoreboard (for server statistics)?

In short: Is there an existing open-source Python interface for the Apache scoreboard IPC facility? I need to collect statistics from a running server WITHOUT using the "mod_status" HTTP interface, and I'd like to avoid Perl if possible. Some background: As I understand it, the Apache web server uses a functionality called the "score...

Stop execution of a script called with execfile

Is it possible to break the execution of a Python script called with the execfile function without using an if/else statement? I've tried exit(), but it doesn't allow main.py to finish. # main.py print "Main starting" execfile("script.py") print "This should print" # script.py print "Script starting" a = False if a == False: # Sa...

Python MySQLdb update query fails

Okay. I've built here a mysql query browser, like navicat. Using MySQLdb to perform queries. Here's the weird part. When i run the query through the program(using MySQLdb), it gives me success, affected rows = 1, but when i look at it in phpmyadmin, the value hasn't changed. so before i perform the query, i print it out, copy and past...

Full-text search on App Engine with Whoosh

I need to do full text searching with Google App Engine. I found the project Whoosh and it works really well, as long as I use the App Engine Development Environement... When I upload my application to App Engine, I am getting the following TraceBack. For my tests, I am using the example application provided in this project. Any idea of ...

"Python.exe" crashes when PyQt's setPixmap() is called with a Pixmap

I have a program that sends and receives images to each other using sockets. The server sends the image data using 'image.tostring()' and the client side receives it and turns it back into an image using 'Image.fromstring', then into a QImage using 'ImageQt.ImageQt(image)', turns it into a QPixmap using 'QPixmap.fromimage(qimage)'then up...

Interpolation in SciPy: Finding X that produces Y

Is there a better way to find which X gives me the Y I am looking for in SciPy? I just began using SciPy and I am not too familiar with each function. import numpy as np import matplotlib.pyplot as plt from scipy import interpolate x = [70, 80, 90, 100, 110] y = [49.7, 80.6, 122.5, 153.8, 163.0] tck = interpolate.splrep(x,y,s=0) xnew =...

Calling a hook function every time an Exception is raised.

Let's say I want to be able to log to file every time any exception is raised, anywhere in my program. I don't want to modify any existing code. Of course, this could be generalized to being able to insert a hook every time an exception is raised. Would the following code be considered safe for doing such a thing? class MyException(E...

PHP desktop applications

Hi, I have quite a few years experience of developing PHP web applications, and have recently started to delve into Python as well. Recently I've been interested in getting into desktop applications as well, but have absolutely no experience in that area. I've seen very little written about PHP-gtk and wonder whether it's really a good ...

Formatting cells in Excel with Python

How do I format cells in Excel with python? In particular I need to change the font of several subsequent rows to be regular instead of bold. Thnak you, Alex ...

Combining nosetests with contracts for Python

I'm using contracts for Python to specify preconditons/postconditions/invariants. I'm also using doctests for doing unit testing. I'd like to have all of my doctest unit tests run with contracts enabled, and I'd like to run my tests using nose. Unfortunately, if I run the tests with nose, it does not execute the pre/post/invariant asse...

How to refuse a recipient in smtpd.SMTPServer.process_message?

Let's say your processing a message in an overridden class like: class MailProcessorServer(smtpd.SMTPServer): def process_message(self, peer, sender, rcpttos, data): badrecipients = [] for rcpt in rcpttos: badrecipients.append(rcpt) #Here I want to warn the sender via a bounced email # that the recipient does no...

Holiday files for G20 countries

Hello, For proper financial FX option pricing I require the exact number of business days between two dates. These dates can be up to 10 years in the future, for 2 different countries. I therefore need to know, in advance the holidays for both of those countries between the two dates. I plan to restrict myself to G20 countries for now. ...

python, unittest: is there a way to pass command line options to the app

I have a module that imports unittest and has some TestCases. I would like to accept some command line options (for example below, the name of a data file), but when I try to pass the option I get the message "option -i not recognized". Is it possible to have unittest + provide options to the app (note: I'm using optparse to handle the o...

What is your wishlist for Python 3.2 (or Python 3.x)?

I've just read the What's New in Python 3.1 text (and I like many things). What's your idea of the thing that didn't go there but you would like to see in the future Python versions? ...