# shell window interaction (IDLE window saved text).


# earlier log (first morning) code is not available
# but see other-INTERACTIVE-LOG.txt for similar early
# code taken from a previous class's interaction log.


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.
>>> name = {'first': 'Bob', 'last': 'Smith'}
>>> jobs = ['dev', 'mgr']
>>> 
>>> rec = {'name': name,
           'jobs': jobs,
           'age':  40 + 10}
>>> rec
{'age': 50, 'jobs': ['dev', 'mgr'], 'name': {'last': 'Smith', 'first': 'Bob'}}
>>> 
>>> rec['pets'] = ['spot', 'fido']
>>> rec
{'age': 50, 'jobs': ['dev', 'mgr'], 'name': {'last': 'Smith', 'first': 'Bob'}, 'pets': ['spot', 'fido']}
>>>
>>>
>>> 
>>> {1, 2, 3, 1, 2, 3, 4, 5, 6}
set([1, 2, 3, 4, 5, 6])
>>> 
>>>
>>>
>>> [x ** 2 for x in [1, 2, 3, 4]]
[1, 4, 9, 16]
>>>
>>> (x ** 2 for x in [1,  2, 3, 4])
<generator object <genexpr> at 0x000000000270C678>
>>>
>>> {x ** 2 for x in [1, 2, 3, 4]}
set([16, 1, 4, 9])
>>>
>>> {x: x** 2 for x in [1, 2, 3, 4]}
{1: 1, 2: 4, 3: 9, 4: 16}
>>> 
>>> 
>>> 
>>> 
>>> X = [1, 3, 5]
>>> 
>>> 
>>> 
>>> ans = raw_input('Entre=')
Entre=spam
>>> ans
'spam'
>>> 
>>> 
>>> 
>>> 
>>> '42' + 1

Traceback (most recent call last):
  File "<pyshell#42>", line 1, in <module>
    '42' + 1
TypeError: cannot concatenate 'str' and 'int' objects
>>> 
>>> int('42')
42
>>> str(1)
'1'
>>> int('42') + 1
43
>>> '42' + str(1)
'421'
>>> 
>>> 
>>> 
>>> 
>>> ================================ RESTART ================================
>>> 
Age?50
2500
Age?5
25
Age?stop
>>> ================================ RESTART ================================
>>> 
Age?spam

Traceback (most recent call last):
  File "C:/pyclass/interact.py", line 4, in <module>
    print int(inp) ** 2
ValueError: invalid literal for int() with base 10: 'spam'
>>> 
>>> '123'.isdigit()
True
>>> ================================ RESTART ================================
>>> 
Age?6
36
Age?spam
Bad!Bad!Bad!Bad!Bad!Bad!Bad!Bad!
Age?7
49
Age?stop
>>> ================================ RESTART ================================
>>> 
Age?5
25
Age?5.5
Bad!Bad!Bad!Bad!Bad!Bad!Bad!Bad!
Age?.123E-90

Traceback (most recent call last):
  File "C:/pyclass/interact.py", line 2, in <module>
    inp = raw_input('Age?')
KeyboardInterrupt
>>> 
>>> ================================ RESTART ================================
>>> 
Age?20
400.0
Age?20e+9
Bad!Bad!Bad!Bad!Bad!Bad!Bad!Bad!
Age?
>>> ================================ RESTART ================================
>>> 
Age?6
36.0
Age?6.5
42.25
Age?spam
Bad!Bad!Bad!Bad!Bad!Bad!Bad!Bad!
Age?stop
>>>
>>> 
>>> S = u'\u00c4spam\u00e8'
>>> S
u'\xc4spam\xe8'
>>> 
>>> S = u'\xc4spam\xe8'
>>> len(S)
6
>>> type(S)
<type 'unicode'>
>>> 
>>> 
>>> 
>>> 
>>> ord('s')
115
>>> ord('spam')

Traceback (most recent call last):
  File "<pyshell#86>", line 1, in <module>
    ord('spam')
TypeError: ord() expected a character, but string of length 4 found
>>> 
>>> for c in 'spam':
	print c

	
s
p
a
m
>>> list('spam')
['s', 'p', 'a', 'm']
>>> 
>>> 
>>> for c in 'spam':
	print ord(c)

	
115
112
97
109
>>> 
>>> for c in 'spam':
	print c, '=', ord(c)

	
s = 115
p = 112
a = 97
m = 109
>>> 
>>> L = []
>>> for c in 'spam':
	L.append(ord(c))

	
>>> L
[115, 112, 97, 109]
>>> 
>>> L = map(ord, 'spam')
>>> L
[115, 112, 97, 109]
>>> 
>>> L = [ord(c) for c in 'spam']
>>> L
[115, 112, 97, 109]
>>> chr(115)
's'
>>>
>>>
>>> range(10, 1, -1)
[10, 9, 8, 7, 6, 5, 4, 3, 2]
>>>
>>>
>>>
>>> X = Y = 0
>>> X = X + 1
>>> X
1
>>> Y
0
>>> X = Y = []
>>> X.append(1)
>>> X
[1]
>>> Y
[1]
>>> 
>>> 
>>> X, Y = [], []
>>> X.append(1)
>>> X
[1]
>>> Y
[]
>>> []*2
[]
>>> [[]]*2
[[], []]
>>> 
>>> X, Y = [[]]*2
>>> X.append(1)
>>> X
[1]
>>> Y
[1]
>>>
>>>
>>>
>>> import sys
>>> sys.version
'2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)]'
>>> 
>>> sys.version_info
sys.version_info(major=2, minor=7, micro=3, releaselevel='final', serial=0)
>>> 
>>> 
>>>
>>> L
[115, 112, 97, 109]
>>> L.append(99)
>>> 
>>> L = L.append(88)
>>> print L
None
>>>
>>> 
>>> D = {'a':1, 'b':2, 'c':3}
>>> D
{'a': 1, 'c': 3, 'b': 2}
>>> 
>>> for key in D.keys().sort():
	print key, D[key]

	

Traceback (most recent call last):
  File "<pyshell#154>", line 1, in <module>
    for key in D.keys().sort():
TypeError: 'NoneType' object is not iterable
>>> 
>>> for key in D:
	print key, D[key]

	
a 1
c 3
b 2
>>> for key in sorted(D):
	print key, D[key]

	
a 1
b 2
c 3
>>> 
>>>
>>> import sys
>>> print >> sys.stderr, 'Bad!' * 8
Bad!Bad!Bad!Bad!Bad!Bad!Bad!Bad!
>>> print(1, 2, 3)
(1, 2, 3)
>>> from __future__ import print_function
KeyboardInterrupt
>>> 
>>> import ds
>>> print ds.__doc__

Module documentation
Words Go Here

>>> print ds.square.__doc__

    function documentation
    can we have your liver then?
    
>>> help(ds)
Help on module ds:

NAME
    ds

FILE
    c:\pyclass\ds.py

DESCRIPTION
    Module documentation
    Words Go Here

FUNCTIONS
    square(x)
        function documentation
        can we have your liver then?

DATA
    spam = 40


>>> help(ds.square)
Help on function square in module ds:

square(x)
    function documentation
    can we have your liver then?

>>> 
>>> 
>>>
>>> F = open('script1.py')
>>> F.readline()
'print(2 ** 100)\n'
>>> 
>>> F.readline()
'import sys\n'
>>> F.readline()
'print(sys.path)    # import search path\n'
>>> F.readline()
"x = 'spam'\n"
>>> F.readline()
"print(x + 'NI')\n"
>>> F.readline()
'\n'
>>> F.readline()
''
>>>
>>> 
>>> F = open('script1.py')
>>> F.next()
'print(2 ** 100)\n'
>>> F.next()
'import sys\n'
>>> F.next()
'print(sys.path)    # import search path\n'
>>> F.next()
"x = 'spam'\n"
>>> F.next()
"print(x + 'NI')\n"
>>> F.next()
'\n'
>>> F.next()

Traceback (most recent call last):
  File "<pyshell#189>", line 1, in <module>
    F.next()
StopIteration
>>> 
>>>
>>> for line in open('script1.py'):
	print line.upper(),

	
PRINT(2 ** 100)
IMPORT SYS
PRINT(SYS.PATH)    # IMPORT SEARCH PATH
X = 'SPAM'
PRINT(X + 'NI')

>>> for line in open('script1.py').readlines():
	print line.upper(),

	
PRINT(2 ** 100)
IMPORT SYS
PRINT(SYS.PATH)    # IMPORT SEARCH PATH
X = 'SPAM'
PRINT(X + 'NI')

>>> F = open('script1.py')
>>> F.readline()
'print(2 ** 100)\n'
>>> F.seek(0)
>>> F.readline()
'print(2 ** 100)\n'
>>> 
>>> 
>>> F = open('script1.py')
>>> while True:
	line = F.readline()
	if not line: break
	print line.upper(),

	
PRINT(2 ** 100)
IMPORT SYS
PRINT(SYS.PATH)    # IMPORT SEARCH PATH
X = 'SPAM'
PRINT(X + 'NI')

>>> for line in open('script1.py'):
	print line.upper(),

	
PRINT(2 ** 100)
IMPORT SYS
PRINT(SYS.PATH)    # IMPORT SEARCH PATH
X = 'SPAM'
PRINT(X + 'NI')

>>> data = open('out.txt', 'w')
>>> for line in open('script1.py'):
	print >> data, line.upper(),

	
>>> data = open('out.txt', 'w')
>>> for line in open('script1.py'):
	data.write(line.upper())

	
>>> open('out.txt').read()
"PRINT(2 ** 100)\nIMPORT SYS\nPRINT(SYS.PATH)    # IMPORT SEARCH PATH\nX = 'SPAM'\nPRINT(X + 'NI')\n\n"
>>> 
>>>
>>> D
{'a': 1, 'c': 3, 'b': 2}
>>> 
>>> I = iter(D)
>>> I.next()
'a'
>>> I.next()
'c'
>>> I.next()
'b'
>>> I.next()

Traceback (most recent call last):
  File "<pyshell#224>", line 1, in <module>
    I.next()
StopIteration
>>> 
>>>
>>> for key in D:
	print key

	
a
c
b
>>> 
>>>
>>> with open('script1.py') as F:
	for line in F:
		print line.upper(),

		
PRINT(2 ** 100)
IMPORT SYS
PRINT(SYS.PATH)    # IMPORT SEARCH PATH
X = 'SPAM'
PRINT(X + 'NI')

>>> 
>>> with open('script1.py') as F1, open('out.txt', 'w') as F2:
	for line in F1:
		F2.write(line.upper())

		
>>> 
>>> data = open('out.txt', 'w')
>>> for line in open('script1.py'):
	data.write(line.upper())

	
>>> 
>>>
>>>
>>> L = [1, 2, 3, 4, 5]
>>> for x in L:
	x += 10

	
>>> L
[1, 2, 3, 4, 5]
>>> x
15
>>> 
>>> L
[1, 2, 3, 4, 5]
>>> for i in range(len(L)):
	L[i] += 10

	
>>> L
[11, 12, 13, 14, 15]
>>> 
>>>
>>> M = [x + 10 for x in L]
>>> M
[21, 22, 23, 24, 25]
>>> 
>>> res = []
>>> for x in L:
	res.append(x + 10)

	
>>> res
[21, 22, 23, 24, 25]
>>> 
>>> M = [x + 10 for x in L]
>>> 
>>> map(ord, 'spam')
[115, 112, 97, 109]
>>> 
>>> [ord(c) for c in 'spam']
[115, 112, 97, 109]
>>> 
>>>
>>> F = open('script1.py')
>>> lines = F.readlines()
>>> lines
['print(2 ** 100)\n', 'import sys\n', 'print(sys.path)    # import search path\n', "x = 'spam'\n", "print(x + 'NI')\n", '\n']
>>> 
>>> lines = [line.rstrip() for line in lines]
>>> lines
['print(2 ** 100)', 'import sys', 'print(sys.path)    # import search path', "x = 'spam'", "print(x + 'NI')", '']
>>> 
>>> lines = [line.rstrip() for line in open('script1.py')]
>>> lines
['print(2 ** 100)', 'import sys', 'print(sys.path)    # import search path', "x = 'spam'", "print(x + 'NI')", '']
>>> 
>>> lines = [line.rstrip() for line in open('script1.py') if line[0] == 'i']
>>> lines
['import sys']
>>> 
>>> res = []
>>> for line in open('script1.py'):
	if line[0] == 'i':
		res.append(line.rstrip())

		
>>> res
['import sys']
>>> 
>>> [x + y for x in 'abc' for y in 'xyz']
['ax', 'ay', 'az', 'bx', 'by', 'bz', 'cx', 'cy', 'cz']
>>> 
>>> res = []
>>> for x in 'abc':
	for y in 'xyz':
		res.append(x + y)

		
>>> res
['ax', 'ay', 'az', 'bx', 'by', 'bz', 'cx', 'cy', 'cz']
>>> 
>>>
>>> 
>>> map(None, 'abc', 'lmnopq')
[('a', 'l'), ('b', 'm'), ('c', 'n'), (None, 'o'), (None, 'p'), (None, 'q')]
>>>
>>> zip('abc', 'lmnopq')
[('a', 'l'), ('b', 'm'), ('c', 'n')]
>>> 
>>>
>>> import difflib
>>> help(difflib)
Help on module difflib:

NAME
    difflib - Module difflib -- helpers for computing deltas between objects.

FILE
    c:\python27\lib\difflib.py

DESCRIPTION
...
...etc
...



# awker output

>>> ================================ RESTART ================================
>>> 
['7', '7', '7', '7', '7', '7', '7']
>>> ================================ RESTART ================================
>>> 
7
7
7
7
7
7
7
>>> ================================ RESTART ================================
>>> 
7
7
7
7
7
7
7
++++++++++++++++++++++++++++++++++++++++
7
7
7
7
7
7
7
>>> 
>>> 
>>> 
>>> ================================ RESTART ================================
>>> 
ggg
ggg
ggg
ggg
ggg
ggg
++++++++++++++++++++++++++++++++++++++++
ggg
ggg
ggg
ggg
ggg
ggg
>>> 
>>> 
>>> 
>>> 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']
>>> 
>>> open = 99
>>> open
99
>>> del open
>>> open
<built-in function open>
>>> 
>>> True = False
>>> True
False
>>> __builtin__.True = False
KeyboardInterrupt
>>> 
>>> 
>>>
>>> def maker(X):
	def action(N):
		return X ** N
	return action

>>> F = maker(2)
>>> F
<function action at 0x000000000292EC18>
>>> F(3)
8
>>> G = maker(10)
>>> G
<function action at 0x000000000292ECF8>
>>> G(3)
1000
>>> 
>>> F(2)
4
>>>
>>>
>>>
>>> import time
>>> time.asctime()
'Tue Sep 11 16:43:44 2012'
>>> 
>>>
>>>
>>> {'a': 1, 'b': 2, 'c': 3}
{'a': 1, 'c': 3, 'b': 2}
>>>
>>> dict(a=1, b=2, c=3)
{'a': 1, 'c': 3, 'b': 2}
>>> 
>>> def sumit(a, b, c): return a + b + c

>>> sumit(1, 2, 3)
6
>>> def sumit(*args):
	i = len(args)
	sum = 0
	for x in range(i):
		sum += args[x]
	return sum

>>> sumit(1, 2, 3, 4, 5)
15
>>> sumit('aa', 'bb', 'cc')

Traceback (most recent call last):
  File "<pyshell#373>", line 1, in <module>
    sumit('aa', 'bb', 'cc')
  File "<pyshell#371>", line 5, in sumit
    sum += args[x]
TypeError: unsupported operand type(s) for +=: 'int' and 'str'
>>> 
>>> def sumit(*args):
	sum = args[0]
	for x in args[1:]:
		sum += x
	return sum

>>> sumit(1, 2, 3, 4, 5)
15
>>> sumit('aa', 'bb', 'cc')
'aabbcc'
>>> 
>>> def sumit(sum, *args):
	for x in args:
		sum += x
	return sum

>>>
>>>  sum(1, 2, 3, 4, 5)

Traceback (most recent call last):
  File "<pyshell#390>", line 1, in <module>
    sum(1, 2, 3, 4, 5)
TypeError: sum expected at most 2 arguments, got 5
>>> 
>>> sum([1, 2, 3, 4, 5])
15
>>> sum([1, 2, 3.33, 4, 5])
15.33
>>> int(sum([1, 2, 3.33, 4, 5]))
15
>>> sum([1, 2, 'xx', 4, 5])
KeyboardInterrupt
>>> 
>>>
>>>
>>> import time
>>> time.clock()
2.443576594641432e-06
>>> 
>>> def timer(func):
	start = time.clock()
	for i in range(1000):
		func()
	return time.clock() - start

>>> import os
>>> os.system('sysinfo')  # wrong name
1
>>> print os.popen('systeminfo').read()

Host Name:                 MARK-VAIO
OS Name:                   Microsoft Windows 7 Professional 
OS Version:                6.1.7601 Service Pack 1 Build 7601
OS Manufacturer:           Microsoft Corporation
...
...etc
...



>>> os.system('systeminfo')
0
>>> def timer(reps, func):
	start = time.clock()
	for i in range(reps):
		func()
	return time.clock() - start

>>> def syscall():
	os.system('systeminfo')

	
>>> timer(5, syscall)
11.799836866826524
>>> 
>>> def syscall():
	stdout = os.popen('systeminfo').read()

	
>>> timer(5, syscall)
11.3329221608451
>>> 
>>> def sumit(*args):
	sum = args[0]
	for x in args[1:]:
		sum += x
	return sum

>>> def timer(reps, func, *args):
	start = time.clock()
	for i in range(reps):
		func(*args)
	return time.clock() - start


>>> timer(1000, sumit, 1, 2, 3, 4, 5)
0.0014290035925341726
>>> timer(100000, sumit, 1, 2, 3, 4, 5)
0.08988891989520198
>>> timer(1000000, sumit, 1, 2, 3, 4, 5)
0.6350308208315028
>>>
>>> time.time()
1347468153.845
>>> 
>>> 
>>> def timer(reps, func, *args):
	start = time.clock()
	for i in range(reps):
		func(*args)
	return time.clock() - start

>>> def syscall():
	os.system('systeminfo')

	
>>> timer(5, lambda: os.system('systeminfo'))
12.026596376371572
>>> 
>>> 
>>> 
>>> 
>>> os.popen('dir').read()
' Volume in drive C has no label.\n Volume Serial Number is D093-D1F7\n\n Directory of C:\\pyclass\n\n09/11/2012  03:40 PM    <DIR>          .\n09/11/2012  03:40 PM    <DIR>          ..\n09/11/2012  03:48 PM               271 awker.py\n09/11/2012  09:17 AM                14 data.txt\n09/11/2012  01:48 PM               201 ds.py\n09/11/2012  01:48 PM               379 ds.pyc\n09/11/2012  03:52 PM               198 input.txt\n09/11/2012  11:10 AM               356 interact.py\n08/16/2012  11:28 AM    <DIR>          oracle-aug12\n09/11/2012  03:40 PM               101 out.txt\n09/10/2012  09:10 AM                35 pswd.txt\n09/11/2012  04:38 PM                72 script1.py\n09/10/2012  11:51 AM               218 script1.pyc\n              10 File(s)          1,845 bytes\n               3 Dir(s)  136,440,864,768 bytes free\n'
>>> 
>>> os.popen('dir').readlines()
[' Volume in drive C has no label.\n', ' Volume Serial Number is D093-D1F7\n', '\n', ' Directory of C:\\pyclass\n', '\n', '09/11/2012  03:40 PM    <DIR>          .\n', '09/11/2012  03:40 PM    <DIR>          ..\n', '09/11/2012  03:48 PM               271 awker.py\n', '09/11/2012  09:17 AM                14 data.txt\n', '09/11/2012  01:48 PM               201 ds.py\n', '09/11/2012  01:48 PM               379 ds.pyc\n', '09/11/2012  03:52 PM               198 input.txt\n', '09/11/2012  11:10 AM               356 interact.py\n', '08/16/2012  11:28 AM    <DIR>          oracle-aug12\n', '09/11/2012  03:40 PM               101 out.txt\n', '09/10/2012  09:10 AM                35 pswd.txt\n', '09/11/2012  04:38 PM                72 script1.py\n', '09/10/2012  11:51 AM               218 script1.pyc\n', '              10 File(s)          1,845 bytes\n', '               3 Dir(s)  136,440,864,768 bytes free\n']
>>> 
>>> for line in os.popen('dir'):
	print line.upper(),

	
 VOLUME IN DRIVE C HAS NO LABEL.
 VOLUME SERIAL NUMBER IS D093-D1F7

 DIRECTORY OF C:\PYCLASS

09/11/2012  03:40 PM    <DIR>          .
09/11/2012  03:40 PM    <DIR>          ..
09/11/2012  03:48 PM               271 AWKER.PY
09/11/2012  09:17 AM                14 DATA.TXT
09/11/2012  01:48 PM               201 DS.PY
09/11/2012  01:48 PM               379 DS.PYC
09/11/2012  03:52 PM               198 INPUT.TXT
09/11/2012  11:10 AM               356 INTERACT.PY
08/16/2012  11:28 AM    <DIR>          ORACLE-AUG12
09/11/2012  03:40 PM               101 OUT.TXT
09/10/2012  09:10 AM                35 PSWD.TXT
09/11/2012  04:38 PM                72 SCRIPT1.PY
09/10/2012  11:51 AM               218 SCRIPT1.PYC
              10 FILE(S)          1,845 BYTES
               3 DIR(S)  136,440,864,768 BYTES FREE

>>> 
>>> F = os.popen('dir')
>>> F.readline()
' Volume in drive C has no label.\n'
>>> F.readline()
' Volume Serial Number is D093-D1F7\n'
>>> F.readline()
'\n'
>>> F.readline()
' Directory of C:\\pyclass\n'
>>> F.close()
>>> 
>>>
>>> F = os.popen('dir')
>>> F.read(10)
' Volume in'
>>> F.read(10)
' drive C h'
>>> F.read(10)
'as no labe'
>>>
>>> 
>>> F = os.popen('dir')
>>> F.readlines()[:5]
[' Volume in drive C has no label.\n', ' Volume Serial Number is D093-D1F7\n', '\n', ' Directory of C:\\pyclass\n', '\n']
>>>
>>> 
>>> F = os.popen('dir')
>>> F.read()[:100]
' Volume in drive C has no label.\n Volume Serial Number is D093-D1F7\n\n Directory of C:\\pyclass\n\n09/11'
>>> 
>>>
>>> for line in os.popen('dir'):
	print line,

	
 Volume in drive C has no label.
 Volume Serial Number is D093-D1F7

 Directory of C:\pyclass

09/11/2012  03:40 PM    <DIR>          .
09/11/2012  03:40 PM    <DIR>          ..
09/11/2012  03:48 PM               271 awker.py
09/11/2012  09:17 AM                14 data.txt
09/11/2012  01:48 PM               201 ds.py
09/11/2012  01:48 PM               379 ds.pyc
09/11/2012  03:52 PM               198 input.txt
09/11/2012  11:10 AM               356 interact.py
08/16/2012  11:28 AM    <DIR>          oracle-aug12
09/11/2012  03:40 PM               101 out.txt
09/10/2012  09:10 AM                35 pswd.txt
09/11/2012  04:38 PM                72 script1.py
09/10/2012  11:51 AM               218 script1.pyc
              10 File(s)          1,845 bytes
               3 Dir(s)  136,440,864,768 bytes free
>>> 
>>> 
>>> 
>>> for val in [line.rstrip().split()[6] for line in open('input.txt')]:
      print val

ggg
ggg
ggg
ggg
ggg
ggg
>>> 
>>>
>>> 
>>> def awker(file, col):
       return [line.rstrip().split()[col-1] for line in open(file)]

>>> awker('input.txt', 7)
['ggg', 'ggg', 'ggg', 'ggg', 'ggg', 'ggg']
>>> print ','.join(awker('input.txt', 7))
ggg,ggg,ggg,ggg,ggg,ggg
>>> 
>>>
>>>
>>>
>>> def timer(reps, func, *args):
	best = 2 ** 32
	for i in range(reps):
		start = time.clock()
		res = func(*args)
	        elapsed = time.clock() - start
	        if elapsed < best: best = elapsed
	return (best, res)

>>> timer(1000000, sumit, 1, 2, 3, 4, 5)
(4.887151590082794e-07, 15)
>>> 
>>>
>>>
>>> import timeit
>>> timeit.Timer(stmt="[x ** 2 for x in range(1000)]").timeit(number=1000)
0.09198062146060693
>>> timeit.Timer(stmt="map(lambda x: x ** 2, range(1000))").timeit(number=1000)
0.20030143960866553
>>> timeit.Timer(stmt="res=[]\nfor x in range(1000):\n\tres.append(x ** 2)").timeit(number=1000)
0.15047642412810092
>>> timeit.Timer(stmt="res=[]\nx = 0\nwhile x < 1000:\n res.append(x ** 2)\n x += 1").timeit(number=1000)
0.20450781235831528
>>>
>>> 
>>>
>>> import reallybigname as shortname  
KeyboardInterrupt
>>> 
>>> import sys
>>> sys.path
['C:/pyclass', 'C:\\Python27\\Lib\\idlelib', 'C:\\Windows\\system32\\python27.zip', 'C:\\Python27\\DLLs', 'C:\\Python27\\lib', 'C:\\Python27\\lib\\plat-win', 'C:\\Python27\\lib\\lib-tk', 'C:\\Python27', 'C:\\Python27\\lib\\site-packages']
>>> sys.path.append('C:\\temp')
>>> 
>>>
>>> from sumit import sumit
>>> sumit(1, 2, 3, 4, 5)
15
>>> ================================ RESTART ================================
>>> 
15
>>> import sumit
15
>>> ================================ RESTART ================================
>>> 
15
>>> import sumit
>>> ================================ RESTART ================================
>>> 
15
>>> 
			 
>>> ================================ RESTART ================================
>>> 
ggg
ggg
ggg
ggg
ggg
ggg
++++++++++++++++++++++++++++++++++++++++
ggg
ggg
ggg
ggg
ggg
ggg
['ggg', 'ggg', 'ggg', 'ggg', 'ggg', 'ggg']
ggg,ggg,ggg,ggg,ggg,ggg
>>> 
>>>
>>> dir('spam')
['__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']
>>> 
>>> 'xx' + 'yy'
'xxyy'
>>> 'xx'.__add__('yy')
'xxyy'
>>> 
>>> 
>>>
>>> import timeit
>>> timeit.Timer(stmt="'xxx' + 'yyy'").timeit(number=1000000)
0.03488107845786858
>>> timeit.Timer(stmt="'xxx'.__add__('yyy')").timeit(number=1000000)
0.17978956895797538
>>> 
>>> timeit.Timer(stmt="len('xxx')").timeit(number=1000000)
0.0943029966557205
>>> timeit.Timer(stmt="'xxx'.__len__()").timeit(number=1000000)
0.15375912492589805
>>>
>>>
>>>
>>> ================================ RESTART ================================
>>> 
Bob Smith Sue Jones
>>> ================================ RESTART ================================
>>> 
Bob Smith Sue Jones
>>> 
>>> name = 'Bob Smith'
>>> name.split()
['Bob', 'Smith']
>>> name.split()[-1]
'Smith'
>>> ================================ RESTART ================================
>>> 
Bob Smith Sue Jones
Smith
110000.0
>>> ================================ RESTART ================================
>>> 
Bob Smith Sue Jones
Smith
110000.0
>>> ================================ RESTART ================================
>>> 
Bob Smith Sue Jones
Smith
110000.0
<__main__.Person instance at 0x000000000294D808>
>>> ================================ RESTART ================================
>>> 
[Person: Bob Smith, 0]
[Person: Sue Jones, 100000]
Smith
[Person: Sue Jones, 110000.0]
>>> ================================ RESTART ================================
>>> 
[Person: Bob Smith, 0]
[Person: Sue Jones, 100000]
Smith
[Person: Sue Jones, 110000.0]
Jones
[Person: Tom Jones, 60000.0]
>>> import person
>>> help(person)
Help on module person:

NAME
    person

FILE
    c:\pyclass\person.py

CLASSES
    Person
        Manager
    
    class Manager(Person)
     |  Methods defined here:
     |  
     |  giveRaise(self, percent, bonus=0.1)
     |  
     |  ----------------------------------------------------------------------
     |  Methods inherited from Person:
     |  
     |  __init__(self, name, job=None, pay=0)
     |  
     |  __str__(self)
     |  
     |  lastName(self)
    
    class Person
     |  stuff goes here
     |  
     |  Methods defined here:
     |  
     |  __init__(self, name, job=None, pay=0)
     |  
     |  __str__(self)
     |  
     |  giveRaise(self, percent)
     |      percent must be 0..1
     |  
     |  lastName(self)


>>> 
>>> ================================ RESTART ================================
>>> 
>>> import glob
>>> glob.glob('schwab*')
['schwabdb']
>>> 
>>> import shelve
>>> db = shelve.open('schwabdb')
>>> db.keys()
['tom', 'bob', 'sue']
>>> len(db)
3
>>> x = db['bob']
>>> print x
[Person: Bob Smith, 0]
>>> x.lastName()
'Smith'
>>> x.job
>>> 
>>> for key in db:
	print key, '=>', db[key]

	
tom => [Person: Tom Jones, 50000]
bob => [Person: Bob Smith, 0]
sue => [Person: Sue Jones, 100000]
>>> ================================ RESTART ================================
>>> 
tom = [Person: Tom Jones, 50000]
bob = [Person: Bob Smith, 0]
sue = [Person: Sue Jones, 100000]
>>> ================================ RESTART ================================
>>> 
tom = [Person: Tom Jones, 50000]
bob = [Person: Bob Smith, 0]
sue = [Person: Sue Jones, 110000.0]
>>> ================================ RESTART ================================
>>> 
tom = [Person: Tom Jones, 50000]
bob = [Person: Bob Smith, 0]
sue = [Person: Sue Jones, 121000.0]
>>> ================================ RESTART ================================
>>> 
tom = [Person: Tom Jones, 50000]
bob = [Person: Bob Smith, 0]
sue = [Person: Sue Jones, 133100.0]
>>> ================================ RESTART ================================
>>> 
[Person: Bob Smith, 0]
[Person: Sue Jones, 100000]
Smith
[Person: Sue Jones, 110000.0]
Jones
[Person: Tom Jones, 60000.0]
>>> 


# examples late in class's 3rd day not here (e.g., import this)
# but see other-INTERACTIVE-LOG.txt for similar late
# code taken from a previous class's interaction log.
