python

Genshi table loop

What is wrong with this Genshi template: <html xmlns:py="http://genshi.edgewall.org/"&gt; <head> <title py:content="title"></title> </head> <body> <left> <table py: for="i in range(1, len(ctabl))"> <li py: for="e in ctabl[i]"> ${e} </li> </table> </body> </html> I get this er...

Import Multiple CSV files into MySQL with Python

Hi All, I am trying to use examples that are fun/interesting to me in order to learn MySQL and Python. I am new to both, as I am a finance guy by trade. I have learned quite a bit along the way, but I am at a point where I am not sure where to go. The data files I am looking to import are contained in a zip file, hosted: here I ext...

Munging non-printable characters to dots using string.translate()

So I've done this before and it's a surprising ugly bit of code for such a seemingly simple task. The goal is to translate any non-printable character into a . (dot). For my purposes "printable" does exclude the last few characters from string.printable (new-lines, tabs, and so on). This is for printing things like the old MS-DOS debu...

How can I get part of regex match as a variable in python?

In Perl it is possible to do something like this (I hope the syntax is right...): $string =~ m/lalala(I want this part)lalala/; $whatIWant = $1; I want to do the same in Python and get the text inside the parenthesis in a string like $1. ...

Django Html email adds extra characters to the email body

I'm using Django to send an e-mail which has a text part, and an HTML part. Here's the code: subject = request.session.get('email_subject', None) from_email = request.session.get('user_email', None) to = request.session.get('user_email', None) bcc = [email.strip() for email in request.session.get('email_recipients', Non...

How does wsgi handle multiple request headers with the same name?

In WSGI headers are represented in the environ as 'HTTP_XXX' values. For example the value Cookie: header is stored at the HTTP_COOKIE key of the environ. How are multiple request headers with the same header name represented? ...

django template url function not matching in app

I have a django project set up with an app called pub. I'm trying to set it up so that I can include urls.py from each app (there will be more as I go) in the top-level urls.py. I've also got a template that uses the 'url' function to resolve a url on a view, defined in the openidgae module. The problem is that after the httprequest i...

Is smtplib pure python or implemented in C?

My question is very straight forward: Is smtplib pure python or implemented in C? ...

Anyone know where I can download a zipped Python distribution?

Yeah, kind of random, but I was wondering if anyone could link me to a .zip file containing a Python distribution. I know I could download the installer, so please don't suggest that. :P. ...

Sqlite, and Python floats

I'm creating a financial app and it seems my floats in sqlite are floating around. Sometimes a 4.0 will be a 4.000009, and a 6.0 will be a 6.00006, things like that. How can I make these more exact and not affect my financial calculations? Values are coming from Python if that matters. Not sure which area the messed up numbers are co...

django embedding user id into URL template best practice

I'm building a navigation menu in my django app, and one of the options is "My Account". There are different roles I have for users, but in order for them all to view their profile, I use a generic URL such as http://mysite/user//profile. What's a Django best practice for building this url using templates? Is it simply something like: ...

Algorithm - How to delete duplicate elements in a list efficiently?

There is a list L. It contains elements of arbitrary type each. How to delete all duplicate elements in such list efficiently? ORDER must be preserved Just an algorithm is required, so no import any external library is allowed. Related questions In Python, what is the fastest algorithm for removing duplicates from a list so that all ...

Why does SWIG crash Python when linked to gtkglext?

Anything I link to gtkglext using SWIG crashes Python on exit. Why does this crash? test.i: %module test %{ void test() { printf("Test.\n"); } %} void test(); Session: $ swig -python test.i $ g++ -I/usr/include/python2.6 -shared -fPIC -o _test.so test_wrap.c -lpython2.6 $ python -c 'import test; test.test()' Test. $ g++ -I/usr/i...

Convert a Python list with strings all to lowercase or uppercase

I have a python list variable that contains strings. Is there a python function that can convert all the strings in one pass to lowercase and vice versa, uppercase? Regards ...

Python - Multi-Dimensional Arrays

Python does not provide built-in support for multi-dimensional arrays. I need to develop an 11-dimensional array and a set of functions to operate on it (mostly linear algebra, vector arithmetics). However, no external library import is allowed. I have a code in C and trying to port it to Python: typedef vec3_t float[3]; vec3_t Array[d...

The Pythonic way of organizing modules and packages

Hello, I come from a background where I normally create one file per class. I organize common classes under directories as well. This practice is intuitive to me and it has been proven to be effective in C++, PHP, JavaSript, etc. I am having trouble bringing this metaphor into Python: files are not just files anymore, but they are for...

Using a hash function to give a memorable personality to objects

(Note: The project is in Python.) I'm running a simulation in which I have many objects that I want to show on the screen and manipulate with. There needs to be a way to identify each object, because they'll be moving from place to place abruptly and I want to be able to track which object moved where. What I've been thinking is, to ev...

Python MySQLdb: Update if exists, else insert

I am looking for a simple way to query an update or insert based on if the row exists in the first place. I am trying to use Python's MySQLdb right now. This is how I execute my query: self.cursor.execute("""UPDATE `inventory` SET `quantity` = `quantity`+{1} WHERE `item_number` = {0} ...

What the mechanism use to integrate python with other languages (.Net, Java ....)

Hi everybody, Somebody talking the python's code can embed into C#'s code. What the mechanism to do that? please explain for me. Thanks a lot ...

What is paste script ?

I'm trying to understand what paste script and paster are. The website is far from clear. I used paster to generate pre-made layouts for projects, but I don't get the big picture. As far as I understand, and from the wikipedia entry, it says it's a framework for web frameworks, but that seems reductive. paster create seems to be able t...