python

How to Connect Python to MySQL DataBase ... ?!

Hi All, A question about connecting Python To MySQL DB: How Can I Do That ?! Link, If You Have References or ... ...

csv file column reading and extracting using python

i have the following code... reader=csv.DictReader(open("test1.csv","r")) allrows = list(reader) keepcols = [c for c in allrows[0] if all(r[c] != '0' for r in allrows)] print keepcols writer=csv.DictWriter(open("output1.csv","w"),fieldnames='keepcols',extrasaction='ignore') writer.writerows(allrows) i have a csv file which has about...

Save an email.Message object into a file

Hi, I am trying to modify emails stored as text files. I first import a message like this : import email f = open('filename') msg = email.message_from_file(f) Then, I make all the modifications I want, using the features of the email module. The last step is to save the Message object (msg) in a file. What is the piece of code that ...

wxPython on Mac OS X: creating a wx.Frame without stealing focus

I managed to get it working on Win32 (inheriting from wx.MiniFrame does the trick), on wxGTK (wx.PopupWindow) but whatever I try, when I create a frame on wxMac, my main window loses focus and the new frame gets it. wxMac does not seem to have a way to interact with the native platform (something like GetHandle() on Win32 and GetGTKWidg...

Some advices for creating a WMS service and a desktop client?

Hi, I'm learning to create a WMS service using MapServer and after that I want to develop a PyQt desktop application which will access it. I don't know what is the best way to do that because I have seen a lot of web solutions but it's not what I'm looking for. Neither I know if there are libraries that can help me. Can you give me som...

Manipulate and print to PDF files in a script

I have several pdf files of some lecture slides. I want to do the following: print every pdf file to another pdf file in which there are 6 slides per page and then merge all the resulting files to one big file while making sure that every original file starts on an odd page number (Edit: obviously, it will be printed in duplex) (possibly...

Limit the rate of requests to an API in a CGI script

The script that I'm writing sometimes makes requests to an API and the API requires that requests are limited to a maximum of 1 per second. What is the most straight forward way of limiting my requests to the API to 1 every second? Would it involve storing the current time in a file each time a request is made? ...

How do I sum the columns in 2D list?

Say I've a Python 2D list as below: my_list = [ [1,2,3,4], [2,4,5,6] ] I can get the row totals with a list comprehension: row_totals = [ sum(x) for x in my_list ] Can I get the column totals without a double for loop? Ie, to get this list: [3,6,8,10] ...

Installing GSL on windows and making it available to python package P4 for phylogenetics

I want to use the P4 Python Package on a windows machine. from: [http://www.bmnh.org/~pf/p4.html][1] I have python 2.6 installed and working with numpy ready and realines.py installed. There is a win32-gbu version of GSL installed on my windows machine, from gnuwin32.sourceforge.net/packages/gsl.htm When I try to install P4, using set...

Creating a namedtuple with a custom hash function

Say I have a namedtuple like this: fooTuple = namedtuple("fooTuple", "item1, item2") And I want the following function to be used for hashing: fooHash(self): return hash(self.item1) * (self.item2) I want this because I want the order of item1 and item2 to be irrelevant (I will do the same for the comparison-operator). I thought...

Python library for HTTP support - including Content-Encoding

I have a scraper, which queries different websites. Some of them varyingly use Content-Encoding. And since I'm trying to simulate an AJAX query and need to mimic Mozilla, I need full support. There are multiple HTTP libraries for Python, but neither seems complete: httplib seems pretty low level, more like a HTTP packet sniffer really. ...

how can I get the ip address of the request in a regested function of python xmlrpc server

I'm writing a simple xmlrpc programe in python. something like the following: def foo(data): # I want get the calling client's IP address here... How can I ? server=SimpleXMLRPCServer.SimpleXMLRPCServer((host, port)) server.register_function(foo) server.handle_request() As can be seen in the above, I want to get the client I...

Which web technology to learn for an experienced C++ developer?

Friends, I've got some exp in c++ and now kind of starting my way to J2EE (to survive:))). Meanwhile, I've got a plan to venture in to a web portal my own. But with very little experience in web technology, I'd need to start from scratch. I'm little confused on which way to go and I'm here. PHP, Python or JSP, considering the fact tha...

how to create a temporary directory and get the path / file name in python

how to create a temporary directory and get the path / file name in python ...

Get a subset of a generator

I have a generator function and want to get the first ten items from it; my first attempt was: my_generator()[:10] This doesn't work because generators aren't subscriptable, as the error tells me. Right now I have worked around that with: list(my_generator())[:10] This works since it converts the generator to a list; however, it's ...

I want to write multiple images to an odt file either in python or php

I want to write multiple image files to a odt file. I will be specifying a dir and the script will take it from there thru a loop. But where do i start? I have never done anything like this before! I found this python code, which can convert html 2 python... so we can parse an html first and then call this one. But there is no reference...

Jinja2: Looking for a View-Helper

I'am new to the Jinja2 template engine. Is there something like the view-helpers from Zend Framework? Can i create simple functions and reuse them all over all my template-files? Something like this? #somewhere in my python code: def nice_demo_function(message): """"return a simple message""" return message So i can to use th...

Initialize a django.forms.ModelChoiceField, binded with foreign key, with default value

I have a model that contains a foreign key value, then in the form generated from this model as a ModelChoiceField. I want to auto select the user's (update_author). I've tried the below code, using the initial property. The view creates a formset with the the dates initialized to now() for the empty form. But, I want also the update_au...

Connecting to MSSQL through Web service. Python. Suds. SOAP.

I'm connecting to web service using suds. from suds.client import Client client=Client(url) #then i'm using web servise methods to get table. It is very big table. big_table=client.service.GetVeryBigTable() #nd trying read every row for row in big_table: print row.Id + row.Nmae + row.Description + row.Item1 +...... the ...

Custom function decorator for views that modified the request path

Could someone show me how i could write a login decorator like @redirect_to_home for my views so that it modifies the request.PATH variable to a new a value like / whenever it is applied to a view. I've seen people do quite complex stuff with decorators: I'm yet to figure them out thoroughly. Thanks ...