This file contains 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
(define-macro (p r . otherstuff) | |
`(if (null? (list ,@otherstuff)) | |
(print ,r) | |
(print ,@otherstuff))) | |
(p 'c 'ciao) |
This file contains 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
cd ~/Library/Application\ Support/TextMate/Bundles | |
svn co http://svn.textmate.org/trunk/Review/Bundles/GetBundles.tmbundle/ |
This file contains 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
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | |
<title>Your Website</title> | |
</head> | |
<body> |
This file contains 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
# build a dictionary that maps the ordinals from 32 to 255 | |
# to their ASCII character equivalents eg. 33: '!' | |
# (note that 32 and 160 are spaces) | |
# Python24 by vegaseat 10may2005 | |
import operator | |
print "ASCII values of characters:" | |
print '-'*27 # print 27 dashes, cosmetic | |
This file contains 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 remove_duplicates(seq, idfun=None): | |
# order preserving | |
if idfun is None: | |
def idfun(x): return x | |
seen = {} | |
result = [] | |
for item in seq: | |
marker = idfun(item) | |
# in old Python versions: | |
# if seen.has_key(marker) |
This file contains 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
# if you are on the internet you can access the HTML code of a | |
# given web site | |
# using the urlopen() method/function from the module urllib2 | |
import urllib2 | |
urlStr = 'http://www.python.org/' | |
try: | |
fileHandle = urllib2.urlopen(urlStr) | |
str1 = fileHandle.read() |
This file contains 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
## Functions are objects in the Python language and the parameters that are passed are really "applied" to the function object. | |
To create a function, use the def functionname(parameters): statement, and then define the function in the following code block. Once the function has been defined, you can call it by specifying the function name and passing the appropriate parameters. | |
def fun(name, location, year=2006): | |
print "%s/%s/%d" % (name, location, year) | |
## The first example shows the function being called by passing the parameter values in order. Notice that the year parameter has a default value set in the function definition, which means that this parameter can be omitted and the default value will be used. | |
>>>fun("Teag", "San Diego") |
This file contains 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
## The module namespace is created when a module is imported and the objects within the module are read. The module namespace can be accessed using the .__dict__ attribute of the module object. Objects in the module namespace can be accessed directly using the module name and dot "." syntax. The example shows this by calling the localtime() function of the time module: | |
>>>import time | |
>>>print time.__dict__ | |
{'ctime': <built-in function ctime>, | |
'clock': <built-in function clock>, | |
... 'localtime': <built-in function localtime>} | |
>>> print time.localtime() | |
(2006, 8, 10, 14, 32, 39, 3, 222, 1) |
This file contains 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
ed@rorty:~$ python | |
Python 2.6.4 (r264:75706, Dec 7 2009, 18:43:55) | |
[GCC 4.4.1] on linux2 | |
Type "help", "copyright", "credits" or "license" for more information. | |
>>> import rdflib | |
>>> graph = rdflib.Graph('Sleepycat') | |
>>> graph.open('my-store', create=True) | |
>>> graph.parse('http://dbpedia.org/resource/Semantic_Web') | |
>>> for object in graph.objects(predicate=rdflib.namespace.OWL.sameAs): | |
... print object |
This file contains 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 test | |
test.answer_to_life_the_universe_and_everything | |
# Whoops that's not right, I'd better edit the module.... | |
reload(test) | |
test.answer_to_life_the_universe_and_everything | |
842 |