python

BMP2avi in python

hi I am looking for a python code that takes series of BMP file and merges them into Avi file (and get the parameter frames per second from the user) does anyone has an idea where to begin? Ariel ...

Most Pythonic way of creating an infinite loop with a 'while' statement

Which one is the pythonic way of below two expressions. 1. while 1: 2. while True: edit:Is there a pythonic way out of two above expressions? ...

How can I detect what other copy of Python script is already running

I have a script. It uses GTK. And I need to know if another copy of scrip starts. If it starts window will extend. Please, tell me the way I can detect it. ...

What mutex/locking/waiting mechanism to use when writing a Chat application with Tornado Web Framework

We're implementing a Chat server using Tornado. The premise is simple, a user makes open an HTTP ajax connection to the Tornado server, and the Tornado server answers only when a new message appears in the chat-room. Whenever the connection closes, regardless if a new message came in or an error/timeout occurred, the client reopens the ...

Google App Engine - Is os.environ reset between requests?

Hello I can't think of a way to test this and was hoping someone here knew the answer... I'm storing some request-specific data in os.environ, and was wondering if that data was going to leak to other requests. Does anyone know? Yes I realize that it's normal to use request.environ for this, and usually I do, but I want to store the cu...

RGB Int to RGB - Python

How can I convert an RGB integer to the corresponding RGB tuple (R,G,B)? Seems simple enough, but I can't find anything on google. I know that for every RGB (r,g,b) you have the integer n = r256^2 + g256 + b, how can I solve the reverse in Python, IE given an n, I need the r,g,b values. ...

Is there a built-in or more Pythonic way to try to parse a string to an integer

I had to write the following function to fail gracefully when trying to parse a string to an integer. I would imagine Python has something built in to do this, but I can't find it. If not, is there a more Pythonic way of doing this that doesn't require a separate function? def try_parse_int(s, base=10, val=None): try: return int(s...

Python+SWIG+MinGW - setup.py builds the source and the pyd file, python "cannot find the module"

here's the deal. i'm using MinGW to build a pythonC module using Swig. when i tell python to load the module, it fails and complains that python cannot find the module. the funny thing is that the module is in the same directory (cwd) that i'm running python under and the module is named _mod.pyd. (i also have the generated mod.py file...

unexpected list appearing in python loop

I am new to python and have the following piece of test code featuring a nested loop and I'm getting some unexpected lists generated: import pybel import math import openbabel search = ["CCC","CCCC"] matches = [] #n = 0 #b = 0 print search for n in search: print "n=",n smarts = pybel.Smarts(n) allmol = ...

How to make my Python unit tests to import the tested modules if they are in sister folders?

I am still getting my head around the import statement. If I have 2 folders in the same level: src test How to make the py files in test import the modules in src? Is there a better solution (like put a folder inside another?) ...

How can I get the text between tags using python SAX parser ?

What I need is just get the text of the corresponding tag and persist it into database. Since the xml file is big (4.5GB) I'm using sax. I used the characters method to get the text and put it in a dictionary. However when I'm printing the text at the endElement method I'm getting a new line instead of the text. Here is my code: def ch...

How to check if a page is displaying a specific <img> tag.

What is the best way to determine if a page on a website is REALLY displaying a specific img tag like this <img src=http://domain.com/img.jpg&gt;? A simple string comparison is easy to fool using http comments <!-- -->. Even if the html tag exists it could be deleted with JavaScript. It could also be obscured by placing an image over...

How to get unit test coverage results in Eclipse + Pydev?

I know Eclipse + PyDev has an option Run As => 3 Python Coverage. But all it reports is: Ran 6 tests in 0.001s OK And it says nothing about code coverage. How to get a code coverage report in Pydev? ...

Detect the location of an image within a larger image.

How do you detect the location of an image within a larger image? I have an unmodified copy of the image. This image is then changed to an arbitrary resolution and placed randomly within a much larger image which is of an arbitrary size. No other transformations are conducted on the resulting image. Python code would be ideal, and it...

Verify source of HTTP request

I've got two systems that need to talk. The systems are setup likeso: System A, running Django (Python 2.5) on Google App Engine (GAE) System B, running Django (Python 2.6) on Ubuntu/Linux over Lighttpd (maybe nginx, later) System A will periodically make requests ('requisitions') of System B using Url Fetch. System B has a Django ap...

Converting from ascii to utf-8 with Python

Hello. I have xmpp bot written in python. One of it's plugins is able to execute OS commands and send output to the user. As far as I know output should be unicode-like to send it over xmpp protocol. So I tried to handle it this way: output = os.popen(cmd).read() if not isinstance(output, unicode): output = unicode(output,'utf-8'...

mod_python not detecting files when using open()

I am trying to open a file I have in my /var/www/ directory named cardlist.xml. this is the code I am using. import cgi import os open("./cardlist.xml", "r") def crawlXml(): return 0 My error is MOD_PYTHON ERROR ProcessId: 11361 Interpreter: '127.0.1.1' ServerName: '127.0.1.1' DocumentRoot: '/var/www' ...

How to calculate positions of holes in a game board?

I'm making a game with Python->PyGame->Albow and ran into a problem with board generation. However I'll try to explain the problem in a language agnostic way. I believe it's not related to python. I've split the game board generation into several parts. Part one generates the board holes. Holes are contained in a list/array. Each hole...

Inter-database communications in PostgreSQL

Hi, I am using PostgreSQL 8.4. I really like the new unnest() and array_agg() features; it is about time they realize the dynamic processing potential of their Arrays! Anyway, I am working on web server back ends that uses long Arrays a lot. Their will be two successive processes which will each occur on a different physical machine. E...

How can I send data to a base template in Django?

Let's say I have a django site, and a base template for all pages with a footer that I want to display a list of the top 5 products on my site. How would I go about sending that list to the base template to render? Does every view need to send that data to the render_to_response? Should I use a template_tag? How would you do it? ...