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? ...
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? ...
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 ? ...
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}) # .....
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 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 ...
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...
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...
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...
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...
Is it possible to return the current system calendar format using Python? For example non-Gregorian calendar formats such as the Thai Buddhist calendar. ...
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? ...
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...
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 ...
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 (...
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. ...
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...
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...
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 ...
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...
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 ...