python

numpy: extending arrays along a new axis?

Surely there must be a way to do this... I can't work it out. I have a (9,4) array, and I want to repeat it along a 3rd axis 4096 times... So it becomes simply (9,4,4096), with each value from the 9,4 array simply repeated 4096 times down the new axis. If my dubious 3D diagram makes sense (the diagonal is a z-axis) 4| /off to 4096 3...

Debugging techniques for Google App Engine development with Python

I'm new to both Python and Google App Engine development and find myself at a loss on how to effectively debug my apps during development. I come from a C#/ASP.NET background where I can typically step through the code in Visual Studio. However, when using a text editor and running dev_appserver.py from a command line, I don't have the...

Making user-made HTML templates safe

I want to allow users to create tiny templates that I then render in Django with a predefined context. I am assuming the Django rendering is safe (I asked a question about this before), but there is still the risk of cross-site-scripting, and I'd like to prevent this. One of the main requirements of these templates is that the user shoul...

How to make a count in python so that the program ends after a particular number of counts?

I'm a newbie and i need to know how to modify a password guessing program to keep track of how many times the user has entered the password wrong. If it has been entered more than 3 times then it should print " This seems to be complicated" and the program should be ended. The password guessing program is password="abcd" while password ...

How to get parameters of fail case in Python unittest?

I'm running an assertEqual test case for a list of methods in a particular class. These methods are expanded from string form to something callable using getattr(). How can I get unittest to tell me the particular method which failed? Meaning: how can I get unittest to print to stdout the particular parameters which caused the failure o...

Linux/Python: Monitor /proc/acpi files without polling?

Is there any way to monitor /proc files, such as /proc/acpi/battery/BAT0/state /proc/acpi/ac_adapter/ADP0/state in a non-polling fashion, similar to inotify on a normal filesystem? I want to do this in a PyGTK app, so I tried using PyGObject's gio.FileMonitor, but no dice. A Python solution that plays well with gtk.main() would be id...

How can I implement a tree in Python? Are there any built in data structures in Python like in Java?

I am trying to construct a general tree. Are there any built in data structures in Python to implement a tree? ...

Secure Python Markdown Library

I'd like to enable users to leave rich text comments, possibly using markdown. I've installed the libraries used on Reddit, but am concerned about the javascript injection attack which occurred last year, especially since I'm still not clear on the details of how the attack was done. Should I still be concerned about comment security? Is...

Making Django development server faster at serving static media

I'm using the Django manage.py runserver for developing my application (obviously), but it takes 10 seconds to completely load a page because the development server is very, very slow at serving static media. Is there any way to speed it up or some kind of workaround? I'm using Windows 7. ...

Database-Independent MAX() Function in SQLAlchemy

I'd like to calculate a MAX() value for a column. What's the proper way to do this in sqlalchemy while preserving database independence? ...

Examples of well written simple PyGTK apps?

I'm looking to get my hands dirty with PyGTK and was wondering if anyone can recommend any relatively simple, really cleanly written PyGTK apps that I can look to for best practices or examples? Any type of app will do, as long as it's simple-ish (i.e., please don't recommend a huge app) and generally considered to be well written. The ...

Can't import numpy into embedded ironpython engine.

From an ipy console I can import ironclad import numpy with no problem. However when I try the same imports with an embedded interpreter the numpy import fails. My Python engines is set up like this: public PyEngine() { //Frames option needed to use sys.__getframe //used in Numpy and others. Dictiona...

If I'm only planning to use MySQL, and if speed is a priority, is there any convincing reason to use SQLAlchemy?

SQLAlchemy seems really heavyweight if all I use is MySQL. Why are convincing reasons for/against the use of SQLAlchemy in an application that only uses MySQL. ...

Python - lexical analysis and tokenization

I'm looking to speed along my discovery process here quite a bit, as this is my first venture into the world of lexical analysis. Maybe this is even the wrong path. First, I'll describe my problem: I've got very large properties files (in the order of 1,000 properties), which when distilled, are really just about 15 important properties...

Are there any existing batch log file aggregation solutions?

I wish to export from multiple nodes log files (in my case apache access and error logs) and aggregate that data in batch, as a scheduled job. I have seen multiple solutions that work with streaming data (i.e think scribe). I would like a tool that gives me the flexibility to define the destination. This requirement comes from the fa...

Prevent Windows 7 Shutdown

I know that shutdown -a will abort a Windows shutdown, but I need to know if there is anything any where I can check for to see if a shutdown is in progress. Ideally, I'd like a small program like this: import os while True: shuttingDown = <shutdown variable to check> if shuttingDown: os.system("shutdown.exe -a") ...

Python's subprocessing with pipes and large files.

I'm trying to use python + ffmpeg + oggenc to convert any audiofile to ogg. The program works, almost. But for big files (i think > ~6mb) the ffmpeg process starts to sleep at pipe_wait. I don't know which pipe it waits for. If I kill the ffmpeg process, the oggenc process continues and I get a resulting ogg-file with about ~2:40 of all...

How can you inspect the stack trace of an exception in Python?

When an exception occurs in Python, can you inspect the stack? Can you determine its depth? I've looked at the traceback module, but I can't figure out how to use it. My goal is to catch any exceptions that occur during the parsing of an eval expression, without catching exceptions thrown by any functions it may have called. Don't be...

Solving embarassingly parallel problems using Python multiprocessing

How does one use multiprocessing to tackle embarrassingly parallel problems? Embarassingly parallel problems typically consist of three basic parts: Read input data (from a file, database, tcp connection, etc.). Run calculations on the input data, where each calculation is independent of any other calculation. Write results of calcula...

OpenID or Auth in Django?

What are the pros and cons of using open id vs auth? Shoud I do both? ...