File: class/Extras/Other/PriorClasses/t2-vancouver-oct15/INTERACTIVE-LOG.py
Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()" for more information. >>> >>> 2 ** 100 1267650600228229401496703205376L >>> 'spam' * 8 'spamspamspamspamspamspamspamspam' >>> >>> import os >>> os.getcwd() 'C:\\Python27' >>> ================================ RESTART ================================ >>> 1267650600228229401496703205376 C:\class SPAMSPAMSPAMSPAMSPAMSPAMSPAMSPAM >>> ================================ RESTART ================================ >>> 1267650600228229401496703205376 C:\class SPAMSPAMSPAMSPAMSPAMSPAMSPAMSPAM >>> ================================ RESTART ================================ >>> 1267650600228229401496703205376 C:\class Traceback (most recent call last): File "C:\class\script1.py", line 5, in <module> X = 'SPAM' + Z NameError: name 'Z' is not defined >>> ================================ RESTART ================================ >>> 1267650600228229401496703205376 C:\class SPAMZSPAMZSPAMZSPAMZSPAMZSPAMZSPAMZSPAMZ >>> >>> os.getcwd() 'C:\\class' >>> import script1 1267650600228229401496703205376 C:\class SPAMZSPAMZSPAMZSPAMZSPAMZSPAMZSPAMZSPAMZ >>> >>> import script1 >>> import script1 >>> import script1 >>> >>> reload(script1) 1267650600228229401496703205376 C:\class SPAMZSPAMZSPAMZSPAMZSPAMZSPAMZSPAMZSPAMZ <module 'script1' from 'C:\class\script1.pyc'> >>> ================================ RESTART ================================ >>> 1267650600228229401496703205376 C:\class SPAMZSPAMZSPAMZSPAMZSPAMZSPAMZSPAMZSPAMZ >>> ================================ RESTART ================================ >>> 1267650600228229401496703205376 C:\class SPAMZSPAMZSPAMZSPAMZSPAMZSPAMZSPAMZSPAMZ >>> >>> >>> >>> >>> X = 'spam' >>> >>> X + 'Ni!' 'spamNi!' >>> X * 8 'spamspamspamspamspamspamspamspam' >>> len(X) 4 >>> X[0] 's' >>> X[1] 'p' >>> X[-1] 'm' >>> X[-1] 'm' >>> X[-2] 'a' >>> X 'spam' >>> X[len(X)-1] 'm' >>> X[-1] 'm' >>> X[1:3] 'pa' >>> X[1:4] 'pam' >>> X[1:] 'pam' >>> X 'spam' >>> X[:-1] 'spa' >>> X[:] 'spam' >>> X[I:J:K] KeyboardInterrupt >>> >>> X = 'abcdefghijklmonp' >>> X[::2] 'acegikmn' >>> X[1::2] 'bdfhjlop' >>> >>> >>> X = 'aaa,bbb,ccc\n' >>> X.replace('bbb', 'SPAM') 'aaa,SPAM,ccc\n' >>> X.find('bbb') 4 >>> X 'aaa,bbb,ccc\n' >>> X.split(',') ['aaa', 'bbb', 'ccc\n'] >>> help(X.find) Help on built-in function find: find(...) S.find(sub [,start [,end]]) -> int Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end]. Optional arguments start and end are interpreted as in slice notation. Return -1 on failure. >>> dir(X) ['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '_formatter_field_name_split', '_formatter_parser', 'capitalize', 'center', 'count', 'decode', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill'] >>> __add__ Traceback (most recent call last): File "<pyshell#54>", line 1, in <module> __add__ NameError: name '__add__' is not defined >>> >>> X 'aaa,bbb,ccc\n' >>> X + 'NI' 'aaa,bbb,ccc\nNI' >>> X.__add__('NI') 'aaa,bbb,ccc\nNI' >>> >>> >>> X 'aaa,bbb,ccc\n' >>> >>> X.replace('bbb', 'SPAM') 'aaa,SPAM,ccc\n' >>> >>> X 'aaa,bbb,ccc\n' >>> >>> X = X.replace('bbb', 'SPAM') >>> X 'aaa,SPAM,ccc\n' >>> >>> >>> X.split(',') ['aaa', 'SPAM', 'ccc\n'] >>> >>> X 'aaa,SPAM,ccc\n' >>> X.strip() 'aaa,SPAM,ccc' >>> >>> X 'aaa,SPAM,ccc\n' >>> >>> X.strip().split(',') ['aaa', 'SPAM', 'ccc'] >>> >>> L = [123, 'anc', 1.23] >>> L + [4, 5, 6] [123, 'anc', 1.23, 4, 5, 6] >>> L * 3 [123, 'anc', 1.23, 123, 'anc', 1.23, 123, 'anc', 1.23] >>> L[-1] 1.23 >>> L[1:] ['anc', 1.23] >>> L [123, 'anc', 1.23] >>> >>> dir(L) ['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__delslice__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getslice__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__setslice__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort'] >>> >>> L [123, 'anc', 1.23] >>> >>> L.append(99) >>> L [123, 'anc', 1.23, 99] >>> L[1] = 'SPAM' >>> L [123, 'SPAM', 1.23, 99] >>> L.remove(1.23) >>> L [123, 'SPAM', 99] >>> >>> L [123, 'SPAM', 99] >>> >>> M = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] >>> >>> M [[1, 2, 3], [4, 5, 6], [7, 8, 9]] >>> >>> M[1] [4, 5, 6] >>> M[1][2] 6 >>> [row[1] for row in M] [2, 5, 8] >>> >>> [sum(row) for row in M] [6, 15, 24] >>> sum([sum(row) for row in M]) 45 >>> >>> M [[1, 2, 3], [4, 5, 6], [7, 8, 9]] >>> sum(sum(row) for row in M) 45 >>> >>> >>> D = {'a': 1, 'b': 2, 'c': 3} >>> D['a'] 1 >>> D['c'] 3 >>> D {'a': 1, 'c': 3, 'b': 2} >>> >>> D['x'] = 'SPAM' >>> D {'a': 1, 'x': 'SPAM', 'c': 3, 'b': 2} >>> D['x'] 'SPAM' >>> >>> D[99] = 'Ni' >>> D {'a': 1, 'x': 'SPAM', 'c': 3, 'b': 2, 99: 'Ni'} >>> >>> D[(1, 2, 3)] = ['l', 'm', 'n'] >>> >>> D {'a': 1, 'c': 3, 'b': 2, (1, 2, 3): ['l', 'm', 'n'], 99: 'Ni', 'x': 'SPAM'} >>> >>> rec = {'name': ['Bob', 'Smith'], 'age': 40.5, 'job': {'main': 'mgr', 'sub': 'dev'}} >>> >>> rec['name'] ['Bob', 'Smith'] >>> rec['name'][-1] 'Smith' >>> >>> rec['job'] {'main': 'mgr', 'sub': 'dev'} >>> rec['job']['main'] 'mgr' >>> >>> rec = 0 >>> rec 0 >>> >>> T = (1, 2, 3) >>> len(T) 3 >>> T + (4, 5, 6) (1, 2, 3, 4, 5, 6) >>> T (1, 2, 3) >>> T[1] = 99 Traceback (most recent call last): File "<pyshell#157>", line 1, in <module> T[1] = 99 TypeError: 'tuple' object does not support item assignment >>> >>> L = [1, 2, 3] >>> T = tuple(L) >>> T (1, 2, 3) >>> T[1] = 99 Traceback (most recent call last): File "<pyshell#162>", line 1, in <module> T[1] = 99 TypeError: 'tuple' object does not support item assignment >>> >>> L [1, 2, 3] >>> L[1] = 99 >>> L [1, 99, 3] >>> >>> S = 'abc' >>> T = tuple(S) >>> T ('a', 'b', 'c') >>> >>> ''.join(T) 'abc' >>> '???'.join(T) 'a???b???c' >>> >>> S 'abc' >>> L = list(S) >>> L ['a', 'b', 'c'] >>> L[1] = '?' >>> ''.join(L) 'a?c' >>> >>> >>> F = open('data.txt', 'w') >>> F.write('hello...\n') >>> F.write('...world\n') >>> F.close() >>> >>> F = open('data.txt') >>> text = F.read() >>> text 'hello...\n...world\n' >>> print text hello... ...world >>> F = open('data.txt', 'rb') >>> text = F.read() >>> text 'hello...\r\n...world\r\n' >>> print text hello... ...world >>> X = 'spam' >>> >>> L = [1, 2] >>> M = L >>> >>> L == M True >>> L is M True >>> >>> L = [1, 2] >>> M = [1, 2] >>> L == M True >>> L is M False >>> msg = """ aaaaaaaaaaaaaaaaaaaa bbbbb'''bb""bbbbb cccccccccc""" >>> msg '\naaaaaaaaaaaaaaaaaaaa\nbbbbb\'\'bb""bbbbb\ncccccccccc' >>> print msg aaaaaaaaaaaaaaaaaaaa bbbbb''bb""bbbbb cccccccccc >>> L [1, 2] >>> >>> L[99] Traceback (most recent call last): File "<pyshell#216>", line 1, in <module> L[99] IndexError: list index out of range >>> L[0:99] [1, 2] >>> >>> >>> D = {'a': 1, 'b': 2} >>> >>> D['c'] Traceback (most recent call last): File "<pyshell#225>", line 1, in <module> D['c'] KeyError: 'c' >>> >>> D.has_key('c') False >>> >>> if not D.has_key('s'): print 'missing...' missing... >>> >>> D.keys() ['a', 'b'] >>> >>> for key in D.keys(): print key, '=>', D[key] a => 1 b => 2 >>> >>> for key in D: print key, '=>', D[key] a => 1 b => 2 >>> >>> [D[key] for key in D] [1, 2] >>> >>> D.values() [1, 2] >>> >>> 'c' in D.keys() False >>> >>> 'c' in D False >>> D.has_key('c') False >>> >>> D {'a': 1, 'b': 2} >>> type(D) <type 'dict'> >>> x = type(D) >>> x <type 'dict'> >>> >>> L = [1, 2, 1, 2, 1, 2, 1, 3, 4, 2, 1] >>> >>> set(L) set([1, 2, 3, 4]) >>> >>> list(set(L)) [1, 2, 3, 4] >>> >>> D {'a': 1, 'b': 2} >>> >>> >>> >>> import pickle >>> f = open('savedict.bin', 'w') >>> pickle.dump(D, f) >>> f.close() >>> >>> D2 = pickle.load(open('savedict.bin')) >>> D2 {'a': 1, 'b': 2} >>> >>> >>> >>> age = '99' >>> age ** 2 Traceback (most recent call last): File "<pyshell#283>", line 1, in <module> age ** 2 TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int' >>> int(age) 99 >>> age '99' >>> int(age) ** 2 9801 >>> ================================ RESTART ================================ >>> Enter age: 10 100 Enter age: 50 2500 Enter age: 999 998001 Enter age: stop bye >>> ================================ RESTART ================================ >>> Enter age: 2 4 Enter age: xxx Traceback (most recent call last): File "C:/class/interact.py", line 4, in <module> print int(ans) ** 2 ValueError: invalid literal for int() with base 10: 'xxx' >>> >>> age = 'xxx' >>> age.isdigit() False >>> >>> ================================ RESTART ================================ >>> Enter age: 99 9801 Enter age: xxx Bad!Bad!Bad!Bad!Bad!Bad!Bad!Bad! Enter age: 9 81 Enter age: stop bye >>> ================================ RESTART ================================ >>> Enter age: 5 25 Enter age: spam Bad!Bad!Bad!Bad!Bad!Bad!Bad!Bad! Enter age: stop bye >>> ================================ RESTART ================================ >>> Enter age: 123 15129 Enter age: 1.23 Bad!Bad!Bad!Bad!Bad!Bad!Bad!Bad! Enter age: 1.23E+99 Bad!Bad!Bad!Bad!Bad!Bad!Bad!Bad! Enter age: stop bye >>> >>> float('1.23E+123') 1.23e+123 >>> ================================ RESTART ================================ >>> Enter age: 10 100.0 Enter age: spam Bad!Bad!Bad!Bad!Bad!Bad!Bad!Bad! Enter age: 123.123 15159.273129 Enter age: 123.123E-99 1.5159273129e-194 Enter age: 3 9.0 Enter age: stop bye >>> >>> A = B = 0 >>> A = A+1 >>> A 1 >>> B 0 >>> A = B = [] >>> A.append(1) >>> A [1] >>> B [1] >>> A, B = [], [] >>> A.append(1) >>> A [1] >>> B [] >>> >>> >>> L = [1, 2] >>> L.append(3) >>> L [1, 2, 3] >>> >>> L = L.append(4) >>> print L None >>> L >>> >>> >>> 'spam' 'spam' >>> print 'spam' spam >>> >>> >>> X = 'spam' >>> for ch in X: print ch s p a m >>> ord('s') 115 >>> ord('spam') Traceback (most recent call last): File "<pyshell#329>", line 1, in <module> ord('spam') TypeError: ord() expected a character, but string of length 4 found >>> >>> >>> D = {'a': 1, 'b': 2, 'c': 3} >>> Ks = D.keys() >>> Ks.sort() >>> >>> for key in D.keys().sort(): KeyboardInterrupt >>> >>> sorted(D.keys()) ['a', 'b', 'c'] >>> >>> for key in sorted(D.keys()): print key, D[key] a 1 b 2 c 3 >>> D.keys() ['a', 'c', 'b'] >>> Ks = D.keys() >>> Ks.sort() >>> >>> >>> import docstrings >>> docstrings.__doc__ '\nModule documentation\nWords Go Here\n' >>> print docstrings.__doc__ Module documentation Words Go Here >>> >>> help(docstrings) Help on module docstrings: NAME docstrings FILE c:\class\docstrings.py DESCRIPTION Module documentation Words Go Here CLASSES SomeClass class SomeClass | class docs go here, and can also | be in nested method def statements FUNCTIONS square(x) function documentation can we have your liver then? DATA spam = 40 >>> help(docstrings.square) Help on function square in module docstrings: square(x) function documentation can we have your liver then? >>> >>> >>> >>> if string == '': KeyboardInterrupt >>> >>> >>> if string: KeyboardInterrupt >>> >>> >>> >>> >>> >>> >>> f = open('script1.py') >>> f.readline() 'print 2 ** 100\n' >>> f.readline() 'import os\n' >>> f.readline() 'print os.getcwd()\n' >>> f.readline() "X = 'SPAM'\n" >>> f.readline() 'print X * 8\n' >>> f.readline() '\n' >>> f.readline() '' >>> >>> >>> f = open('script1.py') >>> f.next() 'print 2 ** 100\n' >>> f.next() 'import os\n' >>> f.next() 'print os.getcwd()\n' >>> f.next() "X = 'SPAM'\n" >>> f.next() 'print X * 8\n' >>> f.next() '\n' >>> f.next() Traceback (most recent call last): File "<pyshell#391>", line 1, in <module> f.next() StopIteration >>> >>> for line in open('script1.py'): print line.upper(), PRINT 2 ** 100 IMPORT OS PRINT OS.GETCWD() X = 'SPAM' PRINT X * 8 >>> [line.rstrip() for line in open('script1.py')] ['print 2 ** 100', 'import os', 'print os.getcwd()', "X = 'SPAM'", 'print X * 8', ''] >>> >>> res = [] >>> for line in open('script1.py'): res.append(line.rstrip()) >>> res ['print 2 ** 100', 'import os', 'print os.getcwd()', "X = 'SPAM'", 'print X * 8', ''] >>> >>> [line.rstrip() for line in open('script1.py') if line[0] == 'p'] ['print 2 ** 100', 'print os.getcwd()', 'print X * 8'] >>> >>> res = [] >>> for line in open('script1.py'): if line[0] == 'p': res.append(line.rstrip()) >>> res ['print 2 ** 100', 'print os.getcwd()', 'print X * 8'] >>> >>> >>> [a + b for a in 'ABC' for b in 'XYZ'] ['AX', 'AY', 'AZ', 'BX', 'BY', 'BZ', 'CX', 'CY', 'CZ'] >>> >>> res = [] >>> for a in 'ABC': for a in 'ABC': res.append(a + b) >>> res ['AZ', 'BZ', 'CZ', 'AZ', 'BZ', 'CZ', 'AZ', 'BZ', 'CZ'] >>> >>> >>> >>> [line.rstrip() for line in open('script1.py')] ['print 2 ** 100', 'import os', 'print os.getcwd()', "X = 'SPAM'", 'print X * 8', ''] >>> >>> G = (line.rstrip() for line in open('script1.py')) >>> G <generator object <genexpr> at 0x0000000002B07750> >>> G.next() 'print 2 ** 100' >>> G.next() 'import os' >>> G.next() 'print os.getcwd()' >>> G.next() "X = 'SPAM'" >>> >>> {line.rstrip() for line in open('script1.py')} set(['', 'import os', "X = 'SPAM'", 'print 2 ** 100', 'print os.getcwd()', 'print X * 8']) >>> >>> >>> {line.rstrip(): 99 for line in open('script1.py')} {'': 99, 'import os': 99, "X = 'SPAM'": 99, 'print 2 ** 100': 99, 'print os.getcwd()': 99, 'print X * 8': 99} >>> >>> {count: line.rstrip() for (count, line) in enumerate(open('script1.py'))} {0: 'print 2 ** 100', 1: 'import os', 2: 'print os.getcwd()', 3: "X = 'SPAM'", 4: 'print X * 8', 5: ''} >>> >>> E = enumerate('spam') >>> E.next() (0, 's') >>> E.next() (1, 'p') >>> E.next() (2, 'a') >>> E.next() (3, 'm') >>> E.next() Traceback (most recent call last): File "<pyshell#454>", line 1, in <module> E.next() StopIteration >>> >>> >>> D {'a': 1, 'c': 3, 'b': 2} >>> >>> for key in D: print key, D[key] a 1 c 3 b 2 >>> >>> for key in D.keys(): print key, D[key] a 1 c 3 b 2 >>> >>> D {'a': 1, 'c': 3, 'b': 2} >>> D.next() Traceback (most recent call last): File "<pyshell#469>", line 1, in <module> D.next() AttributeError: 'dict' object has no attribute 'next' >>> >>> I = iter(D) >>> I.next() 'a' >>> I.next() 'c' >>> I.next() 'b' >>> I.next() Traceback (most recent call last): File "<pyshell#475>", line 1, in <module> I.next() StopIteration >>> F = open('script1.py') >>> iter(F) is F True >>> >>> L = [1, 2, 3, 4] >>> for x in L: x += 10 >>> x 14 >>> L [1, 2, 3, 4] >>> >>> for i in range(len(L)): L[i] += 10 >>> L [11, 12, 13, 14] >>> >>> >>> L [11, 12, 13, 14] >>> E = enumerate(L) >>> E <enumerate object at 0x0000000002B61A20> >>> E.next() (0, 11) >>> E.next() (1, 12) >>> E.next() (2, 13) >>> E.next() (3, 14) >>> E.next() Traceback (most recent call last): File "<pyshell#498>", line 1, in <module> E.next() StopIteration >>> >>> >>> [x for x in seq1 if x in seq2] KeyboardInterrupt >>> >>> >>> __builtin__ Traceback (most recent call last): File "<pyshell#503>", line 1, in <module> __builtin__ NameError: name '__builtin__' is not defined >>> >>> import __builtin__ >>> dir(__builtin__) ['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException', 'BufferError', 'BytesWarning', 'DeprecationWarning', 'EOFError', 'Ellipsis', 'EnvironmentError', 'Exception', 'False', 'FloatingPointError', 'FutureWarning', 'GeneratorExit', 'IOError', 'ImportError', 'ImportWarning', 'IndentationError', 'IndexError', 'KeyError', 'KeyboardInterrupt', 'LookupError', 'MemoryError', 'NameError', 'None', 'NotImplemented', 'NotImplementedError', 'OSError', 'OverflowError', 'PendingDeprecationWarning', 'ReferenceError', 'RuntimeError', 'RuntimeWarning', 'StandardError', 'StopIteration', 'SyntaxError', 'SyntaxWarning', 'SystemError', 'SystemExit', 'TabError', 'True', 'TypeError', 'UnboundLocalError', 'UnicodeDecodeError', 'UnicodeEncodeError', 'UnicodeError', 'UnicodeTranslateError', 'UnicodeWarning', 'UserWarning', 'ValueError', 'Warning', 'WindowsError', 'ZeroDivisionError', '_', '__debug__', '__doc__', '__import__', '__name__', '__package__', 'abs', 'all', 'any', 'apply', 'basestring', 'bin', 'bool', 'buffer', 'bytearray', 'bytes', 'callable', 'chr', 'classmethod', 'cmp', 'coerce', 'compile', 'complex', 'copyright', 'credits', 'delattr', 'dict', 'dir', 'divmod', 'enumerate', 'eval', 'execfile', 'exit', 'file', 'filter', 'float', 'format', 'frozenset', 'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex', 'id', 'input', 'int', 'intern', 'isinstance', 'issubclass', 'iter', 'len', 'license', 'list', 'locals', 'long', 'map', 'max', 'memoryview', 'min', 'next', 'object', 'oct', 'open', 'ord', 'pow', 'print', 'property', 'quit', 'range', 'raw_input', 'reduce', 'reload', 'repr', 'reversed', 'round', 'set', 'setattr', 'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple', 'type', 'unichr', 'unicode', 'vars', 'xrange', 'zip'] >>> >>> and = 1 SyntaxError: invalid syntax >>> open = 1 >>> open 1 >>> del open >>> open <built-in function open> >>> True = False >>> >>> >>> L = [1, 2, 3, 4] >>> >>> for i in range(len(L)): print L[i] 1 2 3 4 >>> for i in range(0, len(L), 2): print L[i] 1 3 >>> L[::2] [1, 3] >>> >>> for x in L: print x, 1 2 3 4 >>> >>> dict(a=1, b=2) {'a': 1, 'b': 2} >>> >>> >>> def func(*args): for x in args: print x >>> func(1, 2, 3) 1 2 3 >>> func(1, 2, 3, 4, 5, 6, 6, 7) 1 2 3 4 5 6 6 7 >>> def sum(*args): tot = args[0] for x in args[1:]: KeyboardInterrupt >>> >>> >>> import script1 1267650600228229401496703205376 C:\class SPAMSPAMSPAMSPAMSPAMSPAMSPAMSPAM >>> >>> import script1 >>> import script1 >>> import script1 >>> import script1 >>> reload(script1) 1267650600228229401496703205376 C:\class SPAMSPAMSPAMSPAMSPAMSPAMSPAMSPAM <module 'script1' from 'C:/class\script1.pyc'> >>> >>> fname = 'script1.py' >>> len(open(fname).read()) 67 >>> len(open(fname).readlines()) 6 >>> tot = 0 >>> for line in open(fname): tot += 1 >>> tot 6 >>> >>> tot = 0 >>> for line in open(fname): tot += len(line) >>> tot 67 >>> ================================ RESTART ================================ >>> Bob Smith Sue Jone 50000 >>> >>> name = 'Bob Smith' >>> name.split() ['Bob', 'Smith'] >>> name.split()[-1] 'Smith' >>> ================================ RESTART ================================ >>> Bob Smith Sue Jones 50000 Smith Jones 55000.0 >>> ================================ RESTART ================================ >>> Bob Smith Sue Jones 50000 Smith Jones 55000.0 >>> ================================ RESTART ================================ >>> Bob Smith Sue Jones 50000 Smith Jones 55000.0 <__main__.Person instance at 0x0000000002B78788> >>> ================================ RESTART ================================ >>> [Person: Bob Smith, 0] [Person: Sue Jones, 50000] Smith Jones [Person: Sue Jones, 55000.0] >>> ================================ RESTART ================================ >>> [Person: Bob Smith, 0] [Person: Sue Jones, 50000] Smith Jones [Person: Sue Jones, 55000.0] Jones [Person: Tom Jones, 72000.0] >>> ================================ RESTART ================================ >>> [Person: Bob Smith, 0] [Person: Sue Jones, 50000] Smith Jones [Person: Sue Jones, 55000.0] Jones [Person: Tom Jones, 72000.0] >>> ================================ RESTART ================================ >>> >>> import glob >>> >>> glob.glob('*') ['data.txt', 'docstrings.py', 'docstrings.pyc', 'interact.py', 'makedb.py', 'person.py', 'person.pyc', 'prior', 'savedict.bin', 'savedict.txt', 'script1.py', 'script1.pyc', 't2db', '__pycache__'] >>> >>> open('t2db', 'rb').read() ...giant line here: start a new shell... Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()" for more information. >>> ================================ RESTART ================================ >>> tom => [Person: Tom Jones, 60000] bob => [Person: Bob Smith, 0] sue => [Person: Sue Jones, 50000] Smith >>> ================================ RESTART ================================ >>> tom => [Person: Tom Jones, 60000] bob => [Person: Bob Smith, 0] sue => [Person: Sue Jones, 50000] Smith >>> ================================ RESTART ================================ >>> tom => [Person: Tom Jones, 60000] bob => [Person: Bob Smith, 0] sue => [Person: Sue Jones, 50000] Smith >>> ================================ RESTART ================================ >>> tom => [Person: Tom Jones, 60000] bob => [Person: Bob Smith, 0] sue => [Person: Sue Jones, 50000] Smith >>> ================================ RESTART ================================ >>> tom => [Person: Tom Jones, 72000.0] bob => [Person: Bob Smith, 0.0] sue => [Person: Sue Jones, 55000.0] Smith >>> ================================ RESTART ================================ >>> tom => [Person: Tom Jones, 86400.0] bob => [Person: Bob Smith, 0.0] sue => [Person: Sue Jones, 60500.0] Smith >>> ================================ RESTART ================================ >>> tom => [Person: Tom Jones, 103680.0] bob => [Person: Bob Smith, 0.0] sue => [Person: Sue Jones, 66550.0] Smith >>> ================================ RESTART ================================ >>> tom => [Person: Tom Jones, 124416.0] bob => [Person: Bob Smith, 0.0] sue => [Person: Sue Jones, 73205.0] Smith >>> try: raise 'spam' except: print 'got it...' got it... >>> >>> >>> import this The Zen of Python, by Tim Peters Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren't special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. Now is better than never. Although never is often better than *right* now. If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. Namespaces are one honking great idea -- let's do more of those! >>> >>> >>> import os >>> os.sep '\\' >>> >>> if sys.version.startswith('3'): KeyboardInterrupt >>> >>> >>> import os >>> len(dir(os)) 125 >>> os.environ.keys() ['TMP', 'PYTHONIOENCODING', 'COMPUTERNAME', 'USERDOMAIN', 'EMC_AUTOPLAY', 'PSMODULEPATH', 'COMMONPROGRAMFILES', 'PROCESSOR_IDENTIFIER', 'PY_PYTHON', 'PROGRAMFILES', 'PROCESSOR_REVISION', 'SYSTEMROOT', 'HOME', 'AMDAPPSDKROOT', 'PROGRAMFILES(X86)', 'WINDOWS_TRACING_FLAGS', 'TK_LIBRARY', 'TEMP', 'COMMONPROGRAMFILES(X86)', 'PROCESSOR_ARCHITECTURE', 'TIX_LIBRARY', 'ALLUSERSPROFILE', 'USERPROFILE', 'LOCALAPPDATA', 'HOMEPATH', 'PROGRAMW6432', 'USERNAME', 'LOGONSERVER', 'SESSIONNAME', 'PROGRAMDATA', 'CLASSPATH', 'TCL_LIBRARY', 'PATH', 'PATHEXT', 'CONFIGSETROOT', 'FP_NO_HOST_CHECK', 'WINDIR', 'WINDOWS_TRACING_LOGFILE', 'HOMEDRIVE', 'RCAUTOPLAY', 'SYSTEMDRIVE', 'COMSPEC', 'NUMBER_OF_PROCESSORS', 'APPDATA', 'PROCESSOR_LEVEL', 'COMMONPROGRAMW6432', 'OS', 'PUBLIC', 'QTJAVA'] >>> >>> os.environ['PATH'] 'C:\\Python33\\;C:\\Program Files\\Common Files\\Microsoft Shared\\Windows Live;C:\\Program Files (x86)\\Common Files\\Microsoft Shared\\Windows Live;C:\\Program Files\\AuthenTec TrueSuite\\;C:\\Program Files\\AuthenTec TrueSuite\\x86;C:\\Program Files (x86)\\Intel\\iCLS Client\\;C:\\Program Files\\Intel\\iCLS Client\\;C:\\Program Files (x86)\\AMD APP\\bin\\x86_64;C:\\Program Files (x86)\\AMD APP\\bin\\x86;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files (x86)\\ATI Technologies\\ATI.ACE\\Core-Static;C:\\Program Files\\Intel\\Intel(R) Management Engine Components\\DAL;C:\\Program Files\\Intel\\Intel(R) Management Engine Components\\IPT;C:\\Program Files (x86)\\Intel\\Intel(R) Management Engine Components\\DAL;C:\\Program Files (x86)\\Intel\\Intel(R) Management Engine Components\\IPT;C:\\Program Files\\Intel\\WiFi\\bin\\;C:\\Program Files\\Common Files\\Intel\\WirelessCommon\\;C:\\Program Files\\Sony\\VAIO Improvement\\;C:\\Program Files (x86)\\Sony\\VAIO Startup Setting Tool;c:\\Program Files (x86)\\Common Files\\Roxio Shared\\DLLShared\\;c:\\Program Files (x86)\\Common Files\\Roxio Shared\\OEM\\DLLShared\\;c:\\Program Files (x86)\\Common Files\\Roxio Shared\\OEM\\DLLShared\\;c:\\Program Files (x86)\\Common Files\\Roxio Shared\\OEM\\12.0\\DLLShared\\;c:\\Program Files (x86)\\Roxio 2010\\OEM\\AudioCore\\;C:\\Program Files (x86)\\Windows Live\\Shared;C:\\Program Files (x86)\\QuickTime\\QTSystem\\;C:\\Program Files (x86)\\Calibre2\\' >>> >>> os.environ['PATH'] = ... KeyboardInterrupt >>> >>> >>> >>> >>> import urllib >>> dir(urllib) ['ContentTooShortError', 'FancyURLopener', 'MAXFTPCACHE', 'URLopener', '__all__', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__version__', '_ftperrors', '_have_ssl', '_hexdig', '_hextochr', '_hostprog', '_is_unicode', '_localhost', '_noheaders', '_nportprog', '_passwdprog', '_portprog', '_queryprog', '_safe_map', '_safe_quoters', '_tagprog', '_thishost', '_typeprog', '_urlopener', '_userprog', '_valueprog', 'addbase', 'addclosehook', 'addinfo', 'addinfourl', 'always_safe', 'base64', 'basejoin', 'c', 'ftpcache', 'ftperrors', 'ftpwrapper', 'getproxies', 'getproxies_environment', 'getproxies_registry', 'i', 'localhost', 'noheaders', 'os', 'pathname2url', 'proxy_bypass', 'proxy_bypass_environment', 'proxy_bypass_registry', 'quote', 'quote_plus', 'reporthook', 'socket', 'splitattr', 'splithost', 'splitnport', 'splitpasswd', 'splitport', 'splitquery', 'splittag', 'splittype', 'splituser', 'splitvalue', 'ssl', 'string', 'sys', 'test1', 'thishost', 'time', 'toBytes', 'unquote', 'unquote_plus', 'unwrap', 'url2pathname', 'urlcleanup', 'urlencode', 'urlopen', 'urlretrieve'] >>> >>> reply = urllib.urlopen('http://www.python.org').read() >>> reply[:1000] '<!doctype html>\n<!--[if lt IE 7]> <html class="no-js ie6 lt-ie7 lt-ie8 lt-ie9"> <![endif]-->\n<!--[if IE 7]> <html class="no-js ie7 lt-ie8 lt-ie9"> <![endif]-->\n<!--[if IE 8]> <html class="no-js ie8 lt-ie9"> <![endif]-->\n<!--[if gt IE 8]><!--><html class="no-js" lang="en" dir="ltr"> <!--<![endif]-->\n\n<head>\n <meta charset="utf-8">\n <meta http-equiv="X-UA-Compatible" content="IE=edge">\n\n <link rel="prefetch" href="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js">\n\n <meta name="application-name" content="Python.org">\n <meta name="msapplication-tooltip" content="The official home of the Python Programming Language">\n <meta name="apple-mobile-web-app-title" content="Python.org">\n <meta name="apple-mobile-web-app-capable" content="yes">\n <meta name="apple-mobile-web-app-status-bar-style" content="black">\n\n <meta name="viewport" content="width=device-width, initial-scale=1.0">\n <meta name="HandheldFriendly" conte' >>>