I'm trying to get the number of times each item in a list is in a string in Python:
paragraph = "I eat bananas and a banana"
def tester(x): return len(re.findall(x,paragraph))
map(tester, ['banana', 'loganberry', 'passion fruit'])
Returns [2, 0, 0]
What I'd like to do however is extend this so I can feed the paragraph value into t...
There comes a point where, in a relatively large sized project, one need to think about splitting the functionality into various functions, and then various modules, and then various packages. Sometimes across different source distributions (eg: extracting a common utility, such as optparser, into a separate project).
The question - how...
I need to complete the plan of a ask-a-question site for my uni. in a few days. I need to have the first version of the code ready for the next Tuesday, while the end of the project is in about three weeks.
Questions about the project which do not fit here
to make efficient tables
to improve a relation figure
to improve a ERD diagram
...
Hi!
Im trying to fix a Python script which takes the posts from a specific RSS feed and strips them down and inputs them into a text file. As you can see beneath, there are two main print functions. One prints only to the shell once run, but it shows all of the posts, which is what I want it to do. Now, the second part is where the prob...
Hello,
I am using python 2.4 and I am having some problems with unicode regular expressions. I have tried to put together a very clear and concise example of my problem. It looks as though there is some problem with how Python is recognizing the different character encodings, or a problem with my understanding. Thank you very much for ...
I want to access some .NET assemblies written in C# from Python code.
A little research showed I have two choices:
IronPython with .NET interface capability/support built-in
Python with the Python .NET package
What are the trade-offs between both solutions?
...
I can't remember which application I was using, but I do recall it having really neat date parsing/interpretation.
For example, you could type in 'two days ago' or 'tomorrow' and it would understand.
Any libraries to suggest? Bonus points if usable from Python.
...
Hi,
I would like to try out the Google App Engine Python environment, which the docs say runs 2.5.2. As I use OS X Leopard, I have Python 2.5.1 installed, but would like the latest 2.5.x version installed (not 2.6 or 3.0). It seems the latest version is 2.5.4
So, I went to here:
http://wiki.python.org/moin/MacPython/Leopard
and sto...
Hi!
Im sure there is a better way to do this, but I am quite the newbie so I did it the only way I could figure it out. The thing is, I have a script that updates a textfile with the newest posts from an RSS feed (I got some help from you guys to figure it out). But I want this script to be automated, so I made this:
import time
import...
Looking for something like PyDoc that can generate a set of Wiki style pages vs the current HTML ones that export out of PyDoc. I would like to be able to export these in Google Code's Wiki as an extension to the current docs up there now.
...
Hi guys,
I am looking for a generic python way to manipulate text into solvable equations.
For example:
there may be some constants to initialize
e1,e2=0.58,0.62
ma1,ma2=0.85,1.15
mw=0.8
Cpa,Cpw=1.023,4.193
dba,dbr=0.0,25.0
and a set of equations (written here for readability rather than the solver)
Q=e1*ma1*Cpa*(tw1-dba)
Q=ma1*Cp...
For a programming exercise I designed for myself, and for use in a pretty non-secure system later on, I'm trying to compare MD5 hashes. The one that is stored in a plain text file and is pulled out by the check_pw() function and the one that is created from the submitted password from a CGI form. md5_pw() is used to create all the hashes...
In a graphical program I'm writing using pygame I use a tuple representing a coordinate like this: (50, 50).
Sometimes, I call a function which returns another tuple such as (3, -5), which represents the change in coordinate.
What is the best way to add the change value to the coordinate value. It would be nice if I could do something ...
With this code:
test.py
import sys
import codecs
sys.stdout = codecs.getwriter('utf-16')(sys.stdout)
print "test1"
print "test2"
Then I run it as:
test.py > test.txt
In Python 2.6 on Windows 2000, I'm finding that the newline characters are being output as the byte sequence \x0D\x0A\x00 which of course is wrong for UTF-16.
Am I...
How can I profile a python script running on mod_wsgi on apache
I would like to use cProfile but it seems it requires me to invoke a function manually. Is there a way to enable cProfile globally and have it keep on logging results.
...
According to the its documentation csv.writer should use '\r\n' as lineterminator by default.
import csv
with open("test.csv", "w") as f:
writer = csv.writer(f)
rows = [(0,1,2,3,4),
(-0,-1,-2,-3,-4),
("a","b","c","d","e"),
("A","B","C","D","E")]
print writer.dialect.lineterminat...
I have a simple django's query set like:
qs = AModel.objects.exclude(state="F").order_by("order")
I'd like to use it as follows:
qs[0:3].update(state='F')
expected = qs[3] # throws error here
But last statement throws:
"Cannot update a query once a slice has been taken."
How can I duplicate the query set?
...
Hello everyone!
I sure hope this won't be an already answered question or a stupid one. Recently I've been programming with several instruments. Trying to communicate between them in order to create a testing program.
However I've encoutered some problems with one specific instrument when I'm trying to call functions that I've "masked"...
So I have been given the task to create a shipping module for a webshop system. It may be a bit overkill, but I would really like to create one that can figure out how to pack parcels in the most optimized way. Having learned programming simply by doing it, this is an area where I have no knowledge - yet! Anyways I can just give short de...
What the .pem file contain? simply a key or a function which generate the key.
I need to create a .pem file and also need to call this file in a function.
here is code to which I have to proceed:
pk = open( 'public_key.pem', 'rb' ).read()
rsa = M2Crypto.RSA.load_pub_key(pk)
...