python

Python csv library with Unicode/UTF-8 support that "just works"

The csv module in Python doesn't work properly when there's UTF-8/Unicode involved. I have found in Python documentation (http://docs.python.org/library/csv.html) and other webpages snippets that work for specific cases, but you have to understand well what encoding you are handling and use the appropiated snippet. Is there any universa...

how to make import conditionally in Python?

I want to do something like this in C: #ifdef SOMETHING do_this(); #endif But in Python this doesn't jive: if something: import module What am I doing wrong? Is this possible in the first place? ...

Reverse of os.path.normcase on Windows

Is there a simple way to get the "real" case sensitive path from a all lower case path. Like the reverse of os.path.normcase. For example, consider the directory: c:\StackOverFlow If I have the following snippet, how to obtain d_real? >>> import os >>> d = os.path.normcase('C:\\StackOverFlow') # convert to lower case >>> d 'c:\\stac...

Python mechanize loses attributes on second open

This is a really specialized case and I feel awkward asking it; however I'm at wits end working on it. I need to follow a tracking number through a form and to a results page so I've been using mechanize in python, the link after form submission is embedded in javascript so I can't simply follow_link. What I want to do is to regex out ...

Django filename from database with non-ascii characters

I'm trying to create a file dynamically in Django: response = HttpResponse(mimetype='text/txt') response['Content-Disposition'] = 'attachment; filename=%s' % filename # UnicodeEncodeError response.write('text') return response If I hardcode the filename it works properly, but if I try to create the filename from DB data that contain...

Django makes strange multiple GET calls on admin-site

My Django-Project is making some strange faned-out GET calls when opening on model from the admin-site and i have no idea where this comes from. I will try to provide as much information possible. Imagine this model called 'Rating', which holds a reference i.e. foreign key to 'Item', 'Usecase' and 'Rater'. So the Item can be rated under...

matching stored keywords/phrases in text

Hi I have a database table with around 1000 keywords/phrases (one to four words long) - This table changes rarely, so I could extract the data into something more useful (like a regular expression?) - So this is not finding / guessing at keywords based on natural language processing.. I then have a user inputting some text into a form ...

the best shortest path algoritm

hello all, what is the difference between the "Floyd-Warshall algorithm" and "Dijkstra's Algorithm", and which is the best for finding the shortest path in a graph? I need to calculate the shortest path between all the pairs in a net and save the results to an array as follows: **A B C D E** A 0 10 15 5 ...

Getting python.exe path at run time

On Windows, how do I find the path to python.exe from within a script at runtime? ...

I'm looking for a cross-platform Python library that can play MP3 and OGG and support ALSA or similar.

There are several different audio libraries, however, none of them meet my exact needs: - It needs to be cross-platform. - It needs to be able to use the ALSA, PulseAudio or any other common default mixer under Linux. - It needs to be able to autodetect the sample frequency. - It needs to be (fairly) simple in usage, if instead someone c...

Best XMPP Library for Python Web Application

Hi, I want to learn how to use XMPP and to create a simple web application with real collaboration features. I am writing the application with Python(WSGI), and the application will require javascript enabled because I am going to use jQuery or Dojo. I have downloaded Openfire for the server and which lib to choose? SleekXMPP making tro...

Print function calls with a variable delay / Python

The question is, how can I configure the Python debugger to show me in the console what functions are being called? In order not to see everything flash by, a delay between the function calls would be needed. ...

Python bash pipe

I want to pipe a python script's output to a bash script. What i did so far was i tried to use os.popen(), sys.subprocess(), and tried to give a pipe for an example os.popen('echo "P 1 1 591336 4927369 1 321 " | v.in.ascii -zn out=abcx format=standard --overwrite') but this didn't work, the values "591336" and "4927369" are the variab...

How can I correct corrupted $PYTHONPATH?

Hello, When trying to launch Mercurial(hg) after a restart in my Ubuntu 9.10 Linux Box I got following message: abort: couldn't find mercurial libraries in [/usr/bin /usr/local/lib/python2.6/dist-packages/vipy-0.4-py2.6.egg /usr/local/lib/python2.6/dist-packages/nose-0.11.1-py2.6.egg /usr/local/lib/python2.6/dist-packages/rope-0....

Can anyone explain the difference between XMLRPC, SOAP and also the C# Web Service?

Are they just the same protocol or something different? I am just confused about it. Actually, I want to call a web service written in C# with ASP.NET by Python. I have tried XMLRPC but it seems just did not work. So what is the actually difference among them? Thanks. ...

pymedia installation

hi im trying to install pymedia but it keeps showing the following message: Path for OGG not found. Path for VORBIS not found. Path for FAAD not found. Path for MP3LAME not found. Path for VORBISENC not found. Path for ALSA not found. Continue building pymedia ? i use windows7 64x and windows vista 64x with python 2.6 how can ...

What is the difference between M2Crypto's set_client_CA_list_from_file() and load_verify_info() and when would you use each?

The M2Crypto library has a few CA-related functions on its SSL.Context object, but the documentation is very unclear as to when you would use certain functions and why. In fact, the docs for almost all of them are, "Load CA certs into the context," so it seems possible that they all do the same thing. There are several examples that us...

How can I prevent a Python module from importing itself?

For instance, I want to make a sql alchemy plugin for another project. And I want to name that module sqlalchemy.py. The problem with this is that it prevents me from importing sqlalchemy: #sqlalchemy.py import sqlalchemy This will make the module import itself. I've tried this, but it doesn't seem to work: import sys #Remove the ...

build python program with extensions using py2exe

I'm having a hard time finding py2exe recipes, especially for cases that require c extensions. The following recipe works fine without the "ext_modules" part. With it I get "NameError: name 'Extension' is not defined. from distutils.core import setup import py2exe import matplotlib import os s = os.popen('svnversion') version = s.r...

lxml Changing Unicode Characters

I am using lxml to read through an xml file and change a few details. However, when running it I find that even if I just use lxml to read the file and then write it out again, as below: fil='iTunes Music Library.XML' tre=etree.parse(fil) tre.write('temp.xml') I find Queensrÿche converted to Queensrÿche. Anyone know how to fix th...