python

How to exit the entire application from a Python thread?

How can I exit my entire Python application from one of its threads? sys.exit() only terminates the thread in which it is called, so that is no help. I would not like to use an os.kill() solution, as this isn't very clean. ...

Migration to GAE

What is the best way to migrate MySQL tables to Google Datastore and create python models for them? I have a PHP+MySQL project that I want to migrate to Python+GAE project. So far the big obstacle is migrating the tables and creating corresponding models. Each table is about 110 columns wide. Creating a model for the table manually i...

Chat server with Twisted framework in python can't receive data from flash client

I've develop a chat server using Twisted framework in Python. It works fine with a Telnet client. But when I use my flash client problem appear... (the flash client work find with my old php chat server, I rewrote the server in python to gain performance) The connexion is establish between the flash client and the twisted server: ...

ElementTree in Python 2.6.2 Processing Instructions support?

I'm trying to create XML using the ElementTree object structure in python. It all works very well except when it comes to processing instructions. I can create a PI easily using the factory function ProcessingInstruction(), but it doesn't get added into the elementtree. I can add it manually, but I can't figure out how to add it above...

Precise response to tablet/mouse events in Windows

How can I tell Windows not to do unhelpful pre-processing on tablet pen events? I am programming in Python 2.6, targetting tablet PCs running Windows 7 (though I would like my program to work with little modification on XP with a SMART interactive whiteboard, and for mouse users on Linux/Mac). I've written a program which hooks into the...

calling Objective C functions from Python?

Is there a way to dynamically call an Objective C function from Python? For example, On the mac I would like to call this Objective C function [NSSpeechSynthesizer availableVoices] without having to precompile any special Python wrapper module. ...

Python Modules most worthwhile reading

I have been programming Python for a while and I have a very good understanding of its features, but I would like to improve my coding style. I think reading the source code of the Python Modules would be a good idea. Can anyone recommend any ones in particular? Related Threads: Beginner looking for beautiful and instructional Python ...

In python, how do you launch an Amazon EC2 instance from within a Google App Engine app?

In python, what is the best way to launch an Amazon EC2 instance from within a Google App Engine app? I would like to keep my AWS keys as secure as possible and be able to retrieve the public DNS for the newly launched EC2 instance. ...

Difference between attributes and style tags in lxml

I am trying to learn lxml after having used BeautifulSoup. However, I am not a strong programmer in general. I have the following code in some source html: <p style="font-family:times;text-align:justify"><font size="2"><b><i> The reasons to eat pickles include: </i></b></font></p> Because the text is bolded, I want to pull that tex...

Django slugified urls - how to handle collisions?

I'm currently working on a toy project in Django. Part of my app allows users to leave reviews. I'd like to take the title of the review and slugify it to create a url. So, if a user writes a review called "The best thing ever!", the url would be something like: www.example.com/reviews/the-best-thing-ever. That's all well and good...

Which framework for a project?

I am contemplating between three frameworks: Django, CakePHP and Zend. The project will include social aspect (members), will have a cart/checkout, lots of different forms and very heavy database usage. I would like to write most of my sql by myself but have only basic knowledge of web development. Both PHP and Python will be new languag...

Comparing performance between ruby and python code

I have a memory and CPU intensive problem to solve and I need to benchmark the different solutions in ruby and python on different platforms. To do the benchmark, I need to measure the time taken and the memory occupied by objects (not the entire program, but a selected list of objects) in both python and ruby. Please recommend ways to...

Mapping std::map to Python

Sometimes it makes sense to have a key-ordered dictionary. In C++, this is often implemented with a Red-black tree. But any self-balancing binary search tree will do (fwiw, Knuth is particularly clear on this subject). The best solution I've been able to come up with so far is to take R. McGraw's AVL-tree type and create a wrapper class ...

deploying django to UserDir

I would like to deploy my django pet-project on our student server. We have apache2 with UserDir mod and I don't have access to apache2 config files. How do I deploy? :-D I come from PHP background and I deploy my PHP scripts by uploading them to my public_html dir and everything shows up on http://ourserver.com/~myusername. I read djan...

Python WebkitGtk: How to respond to the default context menu items?

The default context menu contains items like "Open link in new window" and "Download linked file", which don't seem to do anything. I obviously like to react on these items, but can't figure out how, since the port's documentation is a bit sparse. Does anybody know? ...

Python Regex "object has no attribute"

I've been putting together a list of pages that we need to update with new content (we're switching media formats). In the process I'm cataloging pages that correctly have the new content. Here's the general idea of what I'm doing: Iterate through a file structure and get a list of files For each file read to a buffer and, using...

Telnet automation / scripting

I have already checked This Question but could not find what i'm looking for. I am running Windows (the client), and the server is a legacy mainframe type server. Basically I need to write a script, python code or whatever, to send some know commands to the server via telnet, and preferable capture the output. Then return when done. ...

a better way to do ajax in django

The other day I wrote some AJAX for a Django app that i have been working on. I come from Ruby on Rails, so I haven't done much in the way of raw JS. So based on Rails' partials, I something similar to the following in a sort of pseudocode, don't sweat the details: 1) JS function using prototype's Ajax.Updater ('tablediv' being the id...

get the exit code for python program

Hi, I'm running a python program on windowsXP, how can i obtain the exit code after my program ends ? Thanks. ...

Testing for an empty iterator in a Python for... loop

The code below is based on this recipe. However, the key point of the recipe - that it provides a way to break out of the iteration on an iterator if the iterator is empty - doesn't seem to work here, instead behaving in the following undesired ways: If get_yes_no_answer() == False and there are two or more items left in the iterator, ...