Partial application is cool. What functionality does functools.partial offer that you can't get through lambdas?
>>> sum = lambda x, y : x + y
>>> sum(1, 2)
3
>>> incr = lambda y : sum(1, y)
>>> incr(2)
3
>>> def sum2(x, y):
return x + y
>>> incr2 = functools.partial(sum2, 1)
>>> incr2(4)
5
Is functools somehow more efficient, or...
As the server is using gzip encription I am getting an error torrent while downloading.
<?
$path_parts = pathinfo("http://torcache.com/torrent/56A250DC4CD64F6C304631897F1108D413FE76C7.torrent");
$name= $path_parts['basename'];
$d="torrent/".$name;
if(!copy($f,$d))
{
echo "not copied";
}
else
{
echo "copied";
}
?>
Then i used this ...
I'm using GAE 1.3.5 devserver SDK with Python. When I uncomment this line of code, GAEUnit hangs every time I try to run my test suite:
dep_arc_tail_q = db.GqlQuery("SELECT * FROM DependencyArcTail WHERE courses = :1", course)
#problem line
modelutils.applyToResultsOfQuery(lambda tails : modelutils.removeCourseFromTails(course, tails),...
I can not figure out why my code is not working,
key_one= raw_input("Enter key (0 <= key <= 127): ")
if key_one in range(128):
bin_key_one=bin(key_one)[2:]
print bin_key_one
else:
print "You have to enter key (0 <= key <= 127)"
when i enter a number between 0 and 127, it keeps on going to the else!
can some...
How can we retrieve data from datastore where we want to use one element of list property as parameter in google app engine?
...
i am using the s3cmd linux utility to deletes files from our amazon s3 bucket. i have created a function in python which calls the s3cmd command line utility and access and deletes the files amazon s3 bucket.
command= 's3cmd -c .s3cfg del s3://project-bucket/images/testimage.jpg'
os.system(command)
when i run the project through djang...
Say I get a random number between 1 and 127. I change the number to binary and remove the 0b from it with the fallowing code:
key_one= int(raw_input("Enter key (0 <= key <= 127): "))
if key_one in range(128):
bin_key_one=bin(key_one)[2:]
print bin_key_one
else:
print "You have to enter key (0 <= key <= 127)"
Now I want to mak...
They seem to share a lot of the same characteristics but as far as I can tell, Python 2.5 is faster than 1.8.7 by a lot.
Is there a deeper underlying reason behind this?
...
In my script I build a dictionary of keys(albums) mapped to artists(values) so that I can do a quick lookup of what artists made what albums. However, I want the user to be able to find all albums which contain a substring. For example a search on "Light" should return
[Light Chasers] = Cloud Cult and also [Night Light] = Au Revoir Sim...
A primary reason to use wx.SpinCtrl is to restrict the user to input integers, therefore I think that the text inside it would look better if right-aligned.
Is there a way to do this in wxPython?
...
I need to put 3 items in the list.
state..eg(1,2)
action...eg..west
cost....5
list=[(state,action,cost), (state,action,cost).........]
how can i make it in a form of list. For a particular state , action and cost is there. Moreover, if i need only state from the list, i should be able to extract it from the list.same thing goes for ...
I'm trying to query a database, then convert the file-like object it returns to an XML document. Here's what I've been doing:
>>> import urllib, xml.dom.minidom
>>> query = "http://sbol.bhi.washington.edu/openrdf-sesame/repositories/sbol_test?query=select%20distinct%20%3Fname%20%3Ffeaturename%20where%20%7B%3Fpart%20%3Chttp%3A%2F%2Fsbol....
Hi!
I'm writing a SOAP service using python and soaplib. I need to get IP adresses of all clients of the service to store them to the log file. How can I do that?
...
Hi,
I have a Python program where the initiation script looks like this:
if __name__ == "__main__":
main(sys.argv[1:])
To run this, I have to use Shell or Terminal like this:
myscript somefile.xml
The script accepts a file and then does all the rest of the work.
Now, I am trying to run this program on a web server.
SO I use a ...
myfile = open('out.txt', 'a')
myfile.write(caption)
I write something like this whenever my script is run. But after the first run, it keeps on adding same data to the file. How can I check if it's empty or not and tell it to write only if it's empty?
...
I need to implement a finite-state-machine in order to keep track of a few of my Django project models. I already have a similar app doing that but it's heavily coupled with the others apps models and not reusable in any way. So I decided to re-factor it.
After a few hours, this is what I came up with:
class StateMachine(models.Model):...
What is the best way to write the contents of a StringIO buf to a file ?
I currently do something like:
buf = StringIO()
fd = open ('file.xml', 'w')
# populate buf
fd.write (buf.getvalue ())
But then all of buf would be loaded in memory at the same time.. ?
...
I am very new to Python and am looking to use it to parse a text file. The file has between 250-300 lines of the following format:
---- Mark Grey ([email protected]) changed status from Busy to Available @ 14/07/2010 16:32:36 ----
---- Silvia Pablo ([email protected]) became Available @ 14/07/2010 16:32:39 ----
I need to store the f...
Since there is a python 3.x, why don't we use it?
Why do we still use 2.x?What's the difference?
...
Hi !
Ok ... It might be a stupid question ... but I'm not finding the answer right now !
I need to realize the copy of an object, for which I want all the attributes to be copied, except one or two for which I want to fully control the copy.
Here is the standard copying behaviour for an object :
>>> class test(object):
... def __...