This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def sqrt(x) | |
| square = lambda { |a| a * a } | |
| average = lambda { |a,b| (a + b)/2.0 } | |
| is_good_enough = lambda { |a| (square[a] - x).abs < 0.001 } | |
| improve = lambda { |a| average[a, x/a] } | |
| sqrt_iter = lambda { |a| is_good_enough[a] ? a : sqrt_iter[improve[a]] } | |
| sqrt_iter[1.0] | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| setlocal query "twill Python" | |
| go http://www.google.com/ | |
| fv 1 q $query | |
| submit btnI | |
| show |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import re | |
| import mechanize | |
| response = mechanize.urlopen("http://www.google.com/") | |
| print response.read() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import feedparser | |
| d = feedparser.parse("http://planet.python.org/rss20.xml") | |
| print d.feed.title | |
| print d.feed.subtitle | |
| print "============================" | |
| print d.entries[0].title | |
| print d.entries[0].description |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| n = raw_input("Whats your name? ") | |
| print "Hello, " + n + "!" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| print 'tuple is to freeze as list is to thaw' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| sequence = ['a', 'b', 'c'] | |
| seqtxt = "Sequence: %s" | |
| print seqtxt % sequence | |
| glue='-' | |
| gluetxt = "Glue: %s" | |
| print gluetxt % glue | |
| joined = glue.join(sequence) | |
| jointxt = "Joined: %s" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| sequence = ['a', 'b', 'c'] | |
| seqtxt = "Sequence: %s" | |
| print seqtxt % sequence | |
| glue='-' | |
| gluetxt = "Glue: %s" | |
| print gluetxt % glue | |
| joined = glue.join(sequence) | |
| jointxt = "Joined: %s" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| import subprocess | |
| subprocess.call(["ls", "-l","/tmp"]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| import subprocess | |
| uname = "uname" | |
| uname_arg = "-a" | |
| print "Gathering system information with %s command:\n" % uname | |
| subprocess.call([uname, uname_arg]) | |
| diskspace = "df" | |
| diskspace_arg = "-h" |
OlderNewer