Python 2.5.2 (r252:60911, Feb 22 2008, 07:57:53) [GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin Type "copyright", "credits" or "license()" for more information. **************************************************************** Personal firewall software may warn about the connection IDLE makes to its subprocess using this computer's internal loopback interface. This connection is not visible on any external interface and no data is sent to or received from the Internet. **************************************************************** IDLE 1.2.2 >>> os.getcwd() Traceback (most recent call last): File "", line 1, in os.getcwd() NameError: name 'os' is not defined >>> import os >>> os.getcwd() '/Users/robfelty/RobsDocs/teaching/Ling555-programming/slides/20080929' >>> import 20080929 SyntaxError: invalid syntax >>> import examples Traceback (most recent call last): File "", line 1, in import examples File "/Users/robfelty/RobsDocs/teaching/Ling555-programming/slides/20080929/examples.py", line 3 escaped="Before adding text to SQL databases, all single \\'\\' and double ^ SyntaxError: EOL while scanning single-quoted string >>> escaped="Before adding text to SQL databases, all single \\'\\' and double quote \\\"\\\" characters (as well as the backslash character \\\\ itself) must be escaped with the backslash \\\"\\\\\\\" character." SyntaxError: EOL while scanning single-quoted string >>> import examples Before adding text to SQL databases, all single \'\' and double quote \"\" characters (as well as the backslash character \\ itself) must be escaped with the backslash \"\\\" character. Rob: 555-6785 Traceback (most recent call last): File "", line 1, in import examples File "/Users/robfelty/RobsDocs/teaching/Ling555-programming/slides/20080929/examples.py", line 21, in lolododol NameError: name 'lolododol' is not defined >>> import os >>> import 20080929 SyntaxError: invalid syntax >>> import examples Before adding text to SQL databases, all single \'\' and double quote \"\" characters (as well as the backslash character \\ itself) must be escaped with the backslash \"\\\" character. Rob: 555-6785 forest green ['djefford', 'mabdulma', 'robfelty'] [{'color': 'red', 'nickname': 'Dustin'}, {'color': 'orange', 'nickname': 'Muhammad'}, {'color': 'forest green', 'nickname': 'rob'}] ['djefford', 'mabdulma', 'robfelty'] [('djefford', {'color': 'red', 'nickname': 'Dustin'}), ('mabdulma', {'color': 'orange', 'nickname': 'Muhammad'}), ('robfelty', {'color': 'forest green', 'nickname': 'rob'})] >>> locals() {'__builtins__': , 'examples': , '__name__': '__main__', 'os': , '__doc__': None} >>> from examples import * >>> locals() {'lololododol': [[[{'bar': {'foo': [15]}}]]], '__builtins__': , 'theclasslist': [('djefford', {'color': 'red', 'nickname': 'Dustin'}), ('mabdulma', {'color': 'orange', 'nickname': 'Muhammad'}), ('robfelty', {'color': 'forest green', 'nickname': 'rob'})], 'escaped': 'Before adding text to SQL databases, all single \\\'\\\' and double quote \\"\\" characters (as well as the backslash character \\\\ itself) must be escaped with the backslash \\"\\\\\\" character.', 'phonebook': {'rob': '555-6785'}, 'examples': , 'lot': [(1, 1), (1, 2), (2, 1), (2, 2), (3, 2), (4, 3), ('3', 'a')], 'theclass': {'djefford': {'color': 'red', 'nickname': 'Dustin'}, 'mabdulma': {'color': 'orange', 'nickname': 'Muhammad'}, 'robfelty': {'color': 'forest green', 'nickname': 'rob'}}, '__name__': '__main__', 'theclasskeys': ['djefford', 'mabdulma', 'robfelty'], 'os': , '__doc__': None, 'lot_sorted': [(1, 1), (1, 2), (2, 1), (2, 2), (3, 2), (4, 3), ('3', 'a')]} >>> locals().keys() ['lololododol', '__builtins__', 'theclasslist', 'escaped', 'phonebook', 'examples', 'lot', 'theclass', '__name__', 'theclasskeys', 'os', '__doc__', 'lot_sorted'] >>> escaped 'Before adding text to SQL databases, all single \\\'\\\' and double quote \\"\\" characters (as well as the backslash character \\\\ itself) must be escaped with the backslash \\"\\\\\\" character.' >>> print(escaped) Before adding text to SQL databases, all single \'\' and double quote \"\" characters (as well as the backslash character \\ itself) must be escaped with the backslash \"\\\" character. >>> {'lololododol': [[[{'bar': {'foo': [15]}}]]], '__builtins__': , 'theclasslist': [('djefford', {'color': 'red', 'nickname': 'Dustin'}), ('mabdulma', {'color': 'orange', 'nickname': 'Muhammad'}), ('robfelty', {'color': 'forest green', 'nickname': 'rob'})], 'escaped': 'Before adding text to SQL databases, all single \\\'\\\' and double quote \\"\\" characters (as well as the backslash character \\\\ itself) must be escaped with the backslash \\"\\\\\\" character.', 'phonebook': {'rob': '555-6785'}, 'examples': , 'lot': [(1, 1), (1, 2), (2, 1), (2, 2), (3, 2), (4, 3), ('3', 'a')], 'theclass': {'djefford': {'color': 'red', 'nickname': 'Dustin'}, 'mabdulma': {'color': 'orange', 'nickname': 'Muhammad'}, 'robfelty': {'color': 'forest green', 'nickname': 'rob'}}, '__name__': '__main__', 'theclasskeys': ['djefford', 'mabdulma', 'robfelty'], 'os': , '__doc__': None, 'lot_sorted': [(1, 1), (1, 2), (2, 1), (2, 2), (3, 2), (4, 3), ('3', 'a')]} SyntaxError: invalid syntax >>> os.getcwd() '/Users/robfelty/RobsDocs/teaching/Ling555-programming/slides/20080929' >>> print(escaped) Before adding text to SQL databases, all single \'\' and double quote \"\" characters (as well as the backslash character \\ itself) must be escaped with the backslash \"\\\" character. >>> sqlquery='databasename=what's the wordBefore adding text to SQL databases, all single \'\' and double quote \"\" characters (as well as the backslash character \\ itself) must be escaped with the backslash \"\\\" character. SyntaxError: invalid syntax >>> notescaped="Before adding text to SQL databases, all single \'\' and double quote \"\" characters (as well as the backslash character \\ itself) must be escaped with the backslash \"\\\" character. >>> sqlquery='databasename=what's the word" SyntaxError: EOL while scanning single-quoted string >>> notescaped="Before adding text to SQL databases, all single \'\' and double quote \"\" characters (as well as the backslash character \\ itself) must be escaped with the backslash \"\\\" character." >>> KeyboardInterrupt >>> lot [(1, 1), (1, 2), (2, 1), (2, 2), (3, 2), (4, 3), ('3', 'a')] >>> from examples import * >>> locals() {'lololododol': [[[{'bar': {'foo': [15]}}]]], '__builtins__': , 'theclasslist': [('djefford', {'color': 'red', 'nickname': 'Dustin'}), ('mabdulma', {'color': 'orange', 'nickname': 'Muhammad'}), ('robfelty', {'color': 'forest green', 'nickname': 'rob'})], 'escaped': 'Before adding text to SQL databases, all single \\\'\\\' and double quote \\"\\" characters (as well as the backslash character \\\\ itself) must be escaped with the backslash \\"\\\\\\" character.', 'phonebook': {'rob': '555-6785'}, 'examples': , 'lot': [(1, 1), (1, 2), (2, 1), (2, 2), (3, 2), (4, 3), ('3', 'a')], 'theclass': {'djefford': {'color': 'red', 'nickname': 'Dustin'}, 'mabdulma': {'color': 'orange', 'nickname': 'Muhammad'}, 'robfelty': {'color': 'forest green', 'nickname': 'rob'}}, '__name__': '__main__', 'theclasskeys': ['djefford', 'mabdulma', 'robfelty'], 'os': , '__doc__': None, 'lot_sorted': [(1, 1), (1, 2), (2, 1), (2, 2), (3, 2), (4, 3), ('3', 'a')]} >>> type(escaped) >>> type(list) >>> type(sorted) >>> help(list) Help on class list in module __builtin__: class list(object) | list() -> new list | list(sequence) -> new list initialized from sequence's items | | Methods defined here: | | __add__(...) | x.__add__(y) <==> x+y | | __contains__(...) | x.__contains__(y) <==> y in x | | __delitem__(...) | x.__delitem__(y) <==> del x[y] | | __delslice__(...) | x.__delslice__(i, j) <==> del x[i:j] | | Use of negative indices is not supported. | | __eq__(...) | x.__eq__(y) <==> x==y | | __ge__(...) | x.__ge__(y) <==> x>=y | | __getattribute__(...) | x.__getattribute__('name') <==> x.name | | __getitem__(...) | x.__getitem__(y) <==> x[y] | | __getslice__(...) | x.__getslice__(i, j) <==> x[i:j] | | Use of negative indices is not supported. | | __gt__(...) | x.__gt__(y) <==> x>y | | __hash__(...) | x.__hash__() <==> hash(x) | | __iadd__(...) | x.__iadd__(y) <==> x+=y | | __imul__(...) | x.__imul__(y) <==> x*=y | | __init__(...) | x.__init__(...) initializes x; see x.__class__.__doc__ for signature | | __iter__(...) | x.__iter__() <==> iter(x) | | __le__(...) | x.__le__(y) <==> x<=y | | __len__(...) | x.__len__() <==> len(x) | | __lt__(...) | x.__lt__(y) <==> x x*n | | __ne__(...) | x.__ne__(y) <==> x!=y | | __repr__(...) | x.__repr__() <==> repr(x) | | __reversed__(...) | L.__reversed__() -- return a reverse iterator over the list | | __rmul__(...) | x.__rmul__(n) <==> n*x | | __setitem__(...) | x.__setitem__(i, y) <==> x[i]=y | | __setslice__(...) | x.__setslice__(i, j, y) <==> x[i:j]=y | | Use of negative indices is not supported. | | append(...) | L.append(object) -- append object to end | | count(...) | L.count(value) -> integer -- return number of occurrences of value | | extend(...) | L.extend(iterable) -- extend list by appending elements from the iterable | | index(...) | L.index(value, [start, [stop]]) -> integer -- return first index of value | | insert(...) | L.insert(index, object) -- insert object before index | | pop(...) | L.pop([index]) -> item -- remove and return item at index (default last) | | remove(...) | L.remove(value) -- remove first occurrence of value | | reverse(...) | L.reverse() -- reverse *IN PLACE* | | sort(...) | L.sort(cmp=None, key=None, reverse=False) -- stable sort *IN PLACE*; | cmp(x, y) -> -1, 0, 1 | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | __new__ = | T.__new__(S, ...) -> a new object with type S, a subtype of T >>> import os >>> os.getcwd() '/Users/robfelty/RobsDocs/teaching/Ling555-programming/slides/20080929' >>> phonebook {'rob': '555-6785'} >>> 'Rob: %(rob)s' % phonebook 'Rob: 555-6785' >>> phonebook['mary']='555-9087' >>> phonebook['mary'] '555-9087' >>> 'Rob: %(rob)s, Mary: %(mary)s' % phonebook 'Rob: 555-6785, Mary: 555-9087' >>> 'Rob: %s, Mary: %s' % (phonebook['rob'], phonebook['mary']) 'Rob: 555-6785, Mary: 555-9087' >>> locals() {'lololododol': [[[{'bar': {'foo': [15]}}]]], '__builtins__': , 'theclasslist': [('djefford', {'color': 'red', 'nickname': 'Dustin'}), ('mabdulma', {'color': 'orange', 'nickname': 'Muhammad'}), ('robfelty', {'color': 'forest green', 'nickname': 'rob'})], 'escaped': 'Before adding text to SQL databases, all single \\\'\\\' and double quote \\"\\" characters (as well as the backslash character \\\\ itself) must be escaped with the backslash \\"\\\\\\" character.', 'phonebook': {'rob': '555-6785', 'mary': '555-9087'}, 'examples': , 'lot': [(1, 1), (1, 2), (2, 1), (2, 2), (3, 2), (4, 3), ('3', 'a')], 'theclass': {'djefford': {'color': 'red', 'nickname': 'Dustin'}, 'mabdulma': {'color': 'orange', 'nickname': 'Muhammad'}, 'robfelty': {'color': 'forest green', 'nickname': 'rob'}}, '__name__': '__main__', 'theclasskeys': ['djefford', 'mabdulma', 'robfelty'], 'os': , '__doc__': None, 'lot_sorted': [(1, 1), (1, 2), (2, 1), (2, 2), (3, 2), (4, 3), ('3', 'a')]} >>> lololododol [[[{'bar': {'foo': [15]}}]]] >>> lololododol[0] [[{'bar': {'foo': [15]}}]] >>> lololododol[0][0] [{'bar': {'foo': [15]}}] >>> lololododol[0][0][0]['bar'] {'foo': [15]} >>> lololododol[0][0][0]['bar']['foo'] [15] >>> lololododol[0][0][0]['bar']['foo'][0] 15 >>> theclass['rob']['birthday'] Traceback (most recent call last): File "", line 1, in theclass['rob']['birthday'] KeyError: 'rob' >>> theclass['rob']['birthday']='19781218' Traceback (most recent call last): File "", line 1, in theclass['rob']['birthday']='19781218' KeyError: 'rob' >>> theclass['rob'] Traceback (most recent call last): File "", line 1, in theclass['rob'] KeyError: 'rob' >>> locals() {'lololododol': [[[{'bar': {'foo': [15]}}]]], '__builtins__': , 'theclasslist': [('djefford', {'color': 'red', 'nickname': 'Dustin'}), ('mabdulma', {'color': 'orange', 'nickname': 'Muhammad'}), ('robfelty', {'color': 'forest green', 'nickname': 'rob'})], 'escaped': 'Before adding text to SQL databases, all single \\\'\\\' and double quote \\"\\" characters (as well as the backslash character \\\\ itself) must be escaped with the backslash \\"\\\\\\" character.', 'phonebook': {'rob': '555-6785', 'mary': '555-9087'}, 'examples': , 'lot': [(1, 1), (1, 2), (2, 1), (2, 2), (3, 2), (4, 3), ('3', 'a')], 'theclass': {'djefford': {'color': 'red', 'nickname': 'Dustin'}, 'mabdulma': {'color': 'orange', 'nickname': 'Muhammad'}, 'robfelty': {'color': 'forest green', 'nickname': 'rob'}}, '__name__': '__main__', 'theclasskeys': ['djefford', 'mabdulma', 'robfelty'], 'os': , '__doc__': None, 'lot_sorted': [(1, 1), (1, 2), (2, 1), (2, 2), (3, 2), (4, 3), ('3', 'a')]} >>> theclasslist['rob'] Traceback (most recent call last): File "", line 1, in theclasslist['rob'] TypeError: list indices must be integers >>> theclasslist [('djefford', {'color': 'red', 'nickname': 'Dustin'}), ('mabdulma', {'color': 'orange', 'nickname': 'Muhammad'}), ('robfelty', {'color': 'forest green', 'nickname': 'rob'})] >>> theclasslist['robfelty']['birthday']='19781218 SyntaxError: EOL while scanning single-quoted string >>> theclasslist['robfelty']['birthday']='19781218' Traceback (most recent call last): File "", line 1, in theclasslist['robfelty']['birthday']='19781218' TypeError: list indices must be integers >>> theclasslist['robfelty'] Traceback (most recent call last): File "", line 1, in theclasslist['robfelty'] TypeError: list indices must be integers >>> type(theclasslist) >>> theclass['robfelty'] {'color': 'forest green', 'nickname': 'rob'} >>> theclass['robfelty']['birthday']='19781218' >>> theclass {'djefford': {'color': 'red', 'nickname': 'Dustin'}, 'mabdulma': {'color': 'orange', 'nickname': 'Muhammad'}, 'robfelty': {'color': 'forest green', 'birthday': '19781218', 'nickname': 'rob'}} >>> theclass['djefford']['birthday'] Traceback (most recent call last): File "", line 1, in theclass['djefford']['birthday'] KeyError: 'birthday' >>> theclass['djefford'].has_key('birthday') False >>> print(theclass.keys()) ['djefford', 'mabdulma', 'robfelty'] >>> classkeys=theclass.keys() >>> type(classkeys) >>> classkeys.sort() >>> classkeys ['djefford', 'mabdulma', 'robfelty'] >>> theclasslist [('djefford', {'color': 'red', 'nickname': 'Dustin'}), ('mabdulma', {'color': 'orange', 'nickname': 'Muhammad'}), ('robfelty', {'color': 'forest green', 'birthday': '19781218', 'nickname': 'rob'})] >>> theclasslist.sort() >>> theclasslist [('djefford', {'color': 'red', 'nickname': 'Dustin'}), ('mabdulma', {'color': 'orange', 'nickname': 'Muhammad'}), ('robfelty', {'color': 'forest green', 'birthday': '19781218', 'nickname': 'rob'})] >>> theclasslist.sort(reverse=True) >>> theclasslist [('robfelty', {'color': 'forest green', 'birthday': '19781218', 'nickname': 'rob'}), ('mabdulma', {'color': 'orange', 'nickname': 'Muhammad'}), ('djefford', {'color': 'red', 'nickname': 'Dustin'})] >>> newdict=dict() >>> newdict[('rob', 'felty')]='linux' >>> newdict {('rob', 'felty'): 'linux'} >>> newdict[('rob','felty') ] 'linux' >>> newdict[('rob','felty')] 'linux' >>> newdict['somebody']='windows' >>> newdict {'somebody': 'windows', ('rob', 'felty'): 'linux'} >>> newdict['rob'] Traceback (most recent call last): File "", line 1, in newdict['rob'] KeyError: 'rob' >>> newdict['felty'] Traceback (most recent call last): File "", line 1, in newdict['felty'] KeyError: 'felty' >>> newdict['rob', 'felty'] 'linux' >>> theclasslist [('robfelty', {'color': 'forest green', 'birthday': '19781218', 'nickname': 'rob'}), ('mabdulma', {'color': 'orange', 'nickname': 'Muhammad'}), ('djefford', {'color': 'red', 'nickname': 'Dustin'})] >>> newlist=[4,56,67,98] >>> newlist.index(56) 1 >>>