python

python file manipulation

I have a file with entries such as: 26 1 33 2 . . . and another file with sentences in english I have to write a script to print the 1st word in sentence number 26 and the 2nd word in sentence 33. How do I do it? ...

Python:Which way gives better precision

Is there any difference in precision between one time assignment: res=n/k and multiple assignment in for cycle: for i in range(n): res+=1/k ? ...

Google App Engine: Basic Django Issue

I'm using Django templating with Google App Engine. I'm trying unsuccessfully to print out a menu. The controller: menu_items = {'menu_items': [{'href': '/', 'name': 'Home'}, {'href': '/cart', 'name': 'Cart'}], } render('Views/menu.html', self, {'menu_items': menu_items}) # .....

Simulation of molecular dynamics in Python

I am searching for a python package that I can use to simulate molecular dynamics in non-equilibrium situations. I need a setup that can handle a fairly large number of molecules in a primarily kinetic theory manner, and that can handle having solid surfaces present. With regards to the surfaces, I would need to be able to create arbitra...

Can generateDS be used like xsd.exe

Can I use generateDS.py in python in a similar way that I would use xsd.exe to create C# classes from xsd? Basically, given an xsd schema I want to create a data structure, in python, fill its data in, and then render it into an xml string. perhaps pyXSD is better? oh, and yes, I'm a python newbie ...

How do I drop a bash shell from within Python?

i'm working on a python tcp shell; I'd like to be able to telnet to a port, and have it prompt me with a shell: ex. $ telnet localhost 5555 Connected to localhost. Escape character is '^]'. $ The answer below was quite helpful in getting me on my way. Here's the working code. import SocketServer, os, subprocess class EchoRequestHan...

List fields present in a table

Is there any way to to list out the fields present in a table in django models class Profile(models.Model): user = models.ForeignKey(User, unique=True) name = models.ForeignKey(School) emp = models.ForeignKey(User, unique=True) How to list out the filed names from the table Profile,(just like desc Profile; in mysql ) tha...

Bad file descriptor error

If I try executing the following code f = file('test','rb') fout = file('test.out','wb') for i in range(10): a = f.read(1) fout.write(a) f.close() f = fout f.seek(4) print f.read(4) Where 'test' is any arbitrary file, I get: Traceback (most recent call last): File "testbad.py", line 12, in <module> print f.read(4) IO...

xhtml/rst to excel conversion

I am working on a reporting tool and need to generate reports in various formats including pdf, html and excel(.xls or any format which can be easily opened in excel) I am thinking of generating basic report in xhtml or restructuredtext(rst) and then converting it to other formats, I can use xhtml2pdf or rst2pdf for pdf conversion but I...

Python: Get system calendar format

Is it possible to return the current system calendar format using Python? For example non-Gregorian calendar formats such as the Thai Buddhist calendar. ...

how to geocode phone number

I have a list of phone numbers with area code prefixes that I want to find a latitude/longitude location for. Is there a library (ideally Python) or service that can do this? ...

How can I build a regular expression which has options part

Hi, How can I build a regular expression in python which can match all the following? where it is a "string (a-zA-Z)" follow by a space follow by 1 or multiple 4 integers which separates by a comma: Example: someotherstring 42 1 48 17, somestring 363 1 46 17,363 1 34 17,401 3 8 14, otherstring 42 1 48 17,363 1 34 17, I have tried th...

How to delete all blank lines in the file with the help of python?

For example, we have some file like that: first line second line third line And in result we have to get: first line second line third line Use ONLY python ...

Generate a heatmap in MatPlotLib using a scatter data set

I have a set of X,Y data points (about 10k) that are easy to plot as a scatter plot but that I would like to represent as a heatmap. I looked through the examples in MatPlotLib and they all seem to already start with heatmap cell values to generate the image. Is there a method that converts a bunch of x,y, all different, to a heatmap (...

How do I use Python's httplib to send a POST to a URL, with a dictionary of parameters?

I just want a function that can take 2 parameters: the URL to POST to a dictionary of parameters How can this be done with httplib? thanks. ...

Arguments in the middle of a string to be localized

Hello, I'm a beginner in Python. My problem is pretty simple. I have a string to be localized in a python application containing parameters : print _('Hello dear user, your name is ') + params['first_name'] + ' ' + params['last_name'] + _(' and blah blah blah') This actually does the job, but is not really what I would call a nice wa...

How do I ensure I always get a list of matches from Python's Regular Expressions?

I'm trying to pull some information (no recursion necessary) from a jsp page (malformed xml) similar to this: <td> <html:button ...></html:button> <html:submit ...></html:submit></td> And a regex: <html:(button|submit|cancel)[\s\S]*?</html:(button|submit|cancel)> re.findall() is giving me a list of tuples, like so: [('button','but...

SOAP 1.2 python client

Hi, I am looking for a python SOAP 1.2 client but it seems that it does not exist . All of the existing clients are either not maintainted or only compatible with SOAP 1.1: suds SOAPpy ZSI ...

Python stream http client with keep-alive

Hi. I need a python http client that can reuse connections and that supports consuming the stream as it comes in. It will be used to parse xml streams, sax style. I came up with a solution, but I'm not sure it is the best one (there are quite a few ways of writing an http client in python) class Downloader(): def __init__(self, h...

best way to do this string conversion in Python

Hi, I need to convert a string to another which has removed anything before the second word Example from this, string = "xyz anything else" string2 = "xyz anything else" string3 = "xyz anything else" to this, string = "anything else" string2 = "anything else" string3 = "anything else" The way I've done it doesnt please me at ...