Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] on win32
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      
>>> import docstrings
>>> print docstrings.__doc__

Module documentation
Words Go Here

>>> print docstrings.square.__doc__

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

NAME
    docstrings

FILE
    c:\python25\docstrings.py

DESCRIPTION
    Module documentation
    Words Go Here

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?

>>> 
>>> 
>>> f = open('sgapr08.py')
>>> f.readline()
'# words go here\n'
>>> f.readline()
'print 2 ** 1000\n'
>>> f.readline()
'import sys\n'
>>> f.readline()
'print sys.platform      # platform name\n'
>>> f.readline()
"x = 'Spam!'\n"
>>> f.readline()
'print x * 20\n'
>>> f.readline()
'raw_input()\n'
>>> f.readline()
''
>>> 
>>> f = open('sgapr08.py')
>>> f.next()
'# words go here\n'
>>> f.next()
'print 2 ** 1000\n'
>>> f.next()
'import sys\n'
>>> f.next()
'print sys.platform      # platform name\n'
>>> f.next()
"x = 'Spam!'\n"
>>> f.next()
'print x * 20\n'
>>> f.next()
'raw_input()\n'
>>> f.next()

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

	
# WORDS GO HERE
PRINT 2 ** 1000
IMPORT SYS
PRINT SYS.PLATFORM      # PLATFORM NAME
X = 'SPAM!'
PRINT X * 20
RAW_INPUT()
>>> 
>>> for line in open('sgapr08.py').readlines():
	print line.upper(),

	
# WORDS GO HERE
PRINT 2 ** 1000
IMPORT SYS
PRINT SYS.PLATFORM      # PLATFORM NAME
X = 'SPAM!'
PRINT X * 20
RAW_INPUT()
>>> 
>>> f = open('sgapr08.py')
>>> while True:
	line = f.readline()
	if not line: break
	print line.upper(),

	
# WORDS GO HERE
PRINT 2 ** 1000
IMPORT SYS
PRINT SYS.PLATFORM      # PLATFORM NAME
X = 'SPAM!'
PRINT X * 20
RAW_INPUT()
>>> 
>>> 
>>> X[I:J:K]
KeyboardInterrupt
>>> 
>>> 
>>> S = 'abcdefghijklnmpo'
>>> 
>>> S[0:len(S):2]
'acegiknp'
>>> 
>>> S[::2]
'acegiknp'
>>> S[::2]
'acegiknp'
>>> S[::3]
'adgjno'
>>> 
>>> S
'abcdefghijklnmpo'
>>> S[::-1]
'opmnlkjihgfedcba'
>>> 
>>> S[::2]
'acegiknp'
>>> S[1::2]
'bdfhjlmo'
>>> S
'abcdefghijklnmpo'
>>> 
>>> 
>>> L = [1, 2, 3, 4, 5]
>>> for x in L:
	x += 10

	
>>> 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]
>>> 
>>> S = 'spam'
>>> res = []
>>> for c in S:
	res.append(ord(c))

	
>>> res
[115, 112, 97, 109]
>>> 
>>> res = [ord(c) for c in S]
>>> res
[115, 112, 97, 109]
>>> 
>>> map(ord, S)
[115, 112, 97, 109]
>>> 
>>> f = open('sgapr08.py')
>>> lines = f.readlines()
>>> line
''
>>> lines
['# words go here\n', 'print 2 ** 1000\n', 'import sys\n', 'print sys.platform      # platform name\n', "x = 'Spam!'\n", 'print x * 20\n', 'raw_input()\n']
>>> 
>>> lines = [line.rstrip() for line in lines]
>>> lines
['# words go here', 'print 2 ** 1000', 'import sys', 'print sys.platform      # platform name', "x = 'Spam!'", 'print x * 20', 'raw_input()']
>>> 
>>> lines = [line.rstrip() for line in open('sgapr08.py')]
>>> lines
['# words go here', 'print 2 ** 1000', 'import sys', 'print sys.platform      # platform name', "x = 'Spam!'", 'print x * 20', 'raw_input()']
>>> 
>>> lines = [line.rstrip() for line in open('sgapr08.py') if line[0] == 'p']
>>> lines
['print 2 ** 1000', 'print sys.platform      # platform name', 'print x * 20']
>>> 
>>> res = []
>>> for line in open('sgapr08'):
	if line[0] == 'p':
		res.append(line.rstrip())

		

Traceback (most recent call last):
  File "<pyshell#113>", line 1, in <module>
    for line in open('sgapr08'):
IOError: [Errno 2] No such file or directory: 'sgapr08'
>>> 
>>> for line in open('sgapr08.py'):
	if line[0] == 'p':
		res.append(line.rstrip())

		
>>> res
['print 2 ** 1000', 'print sys.platform      # platform name', 'print x * 20']
>>> 

>>> import __builtin__
>>> dir(__builtin__)
['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException', '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__', 'abs', 'all', 'any', 'apply', 'basestring', 'bool', 'buffer', 'callable', 'chr', 'classmethod', 'cmp', 'coerce', 'compile', 'complex', 'copyright', 'credits', 'delattr', 'dict', 'dir', 'divmod', 'enumerate', 'eval', 'execfile', 'exit', 'file', 'filter', 'float', 'frozenset', 'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex', 'id', 'input', 'int', 'intern', 'isinstance', 'issubclass', 'iter', 'len', 'license', 'list', 'locals', 'long', 'map', 'max', 'min', 'object', 'oct', 'open', 'ord', 'pow', '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 = 42
>>> open
42
>>> 
>>> True = False
>>> True
False
>>> 
>>> __builtin__.True = False
KeyboardInterrupt
>>> 
>>> 
>>> import __builtin__
>>> 

>>> 
>>> 
>>> 

>>> def func(*args):
	for x in args:
		print x

		
>>> func()
>>> func(1)
1
>>> func(1, 2, 3, 4, 5, 6)
1
2
3
4
5
6
>>> def func(*args):
	total = 0
	for x in args:
		total += x
	return total

>>> func(1, 2, 3, 4)
10
>>> func('a', 'b')

Traceback (most recent call last):
  File "<pyshell#147>", line 1, in <module>
    func('a', 'b')
  File "<pyshell#145>", line 4, in func
    total += x
TypeError: unsupported operand type(s) for +=: 'int' and 'str'
>>> 
>>> def func(*args):
	total = ''
	for x in args:
		total += x
	return total

>>> func('a', 'b')
'ab'
>>> 
>>> func(1, 2)

Traceback (most recent call last):
  File "<pyshell#153>", line 1, in <module>
    func(1, 2)
  File "<pyshell#150>", line 4, in func
    total += x
TypeError: cannot concatenate 'str' and 'int' objects
>>> 
>>> def func(*args):
	if type(arg[0]) == str:
		total = ''
	elif type(arg[0]) == int:
		total = 0
	for x in args:
		total += x
	return total

>>> func(1, 2, 3)

Traceback (most recent call last):
  File "<pyshell#157>", line 1, in <module>
    func(1, 2, 3)
  File "<pyshell#156>", line 2, in func
    if type(arg[0]) == str:
NameError: global name 'arg' is not defined
>>> 
>>> 
>>> def func(*args):
	if type(args[0]) == str:
		total = ''
	elif type(args[0]) == int:
		total = 0
	for x in args:
		total += x
	return total

>>> func(1, 2, 3)
6
>>> func('aa', 'bb', 'cc', 'dd')
'aabbccdd'
>>> 
>>> def func(*args):
	total = arg[0]
	for x in args[1:]:
		total += x
	return total

>>> func(1, 2, 3)

Traceback (most recent call last):
  File "<pyshell#167>", line 1, in <module>
    func(1, 2, 3)
  File "<pyshell#166>", line 2, in func
    total = arg[0]
NameError: global name 'arg' is not defined
>>> 
>>> def func(*args):
	total = args[0]
	for x in args[1:]:
		total += x
	return total

>>> func(1, 2)
3
>>> func('aa', 'bb', 'cc')
'aabbcc'
>>> func([1, 1[, [2, 2], [3, 3])
      
SyntaxError: invalid syntax
>>> func([1, 1], [2, 2], [3, 3])
[1, 1, 2, 2, 3, 3]
>>> 
>>> def min(*args):
	res = args[0]
	for x in args[1:]:
		if x < res:
		    res = x
	return res

>>> min(3, 1, 2, 4, 9)
1
>>> 
>>> min('bb', 'aa', 'cc')
'aa'
>>> def func(**args):
	print args

	
>>> func(a=1, b=3, c=2)
{'a': 1, 'c': 2, 'b': 3}
>>> 
>>> def func(**args):
	args = args.values()
	total = args[0]
	for x in args[1:]:
		total += x
	return total

>>> func(a=1, b=3, c=2)
6
>>> import sgapr08
10715086071862673209484250490600018105614048117055336074437503883703510511249361224931983788156958581275946729175531468251871452856923140435984577574698574803934567774824230985421074605062371141877954182153046474983581941267398767559165543946077062914571196477686542167660429831652624386837205668069376
win32
Spam!Spam!Spam!Spam!Spam!Spam!Spam!Spam!Spam!Spam!Spam!Spam!Spam!Spam!Spam!Spam!Spam!Spam!Spam!Spam!

>>> import sgapr08
>>> import sgapr08
>>> import sgapr08
>>> reload(sgapr08)
10715086071862673209484250490600018105614048117055336074437503883703510511249361224931983788156958581275946729175531468251871452856923140435984577574698574803934567774824230985421074605062371141877954182153046474983581941267398767559165543946077062914571196477686542167660429831652624386837205668069376
win32
Spam!Spam!Spam!Spam!Spam!Spam!Spam!Spam!Spam!Spam!Spam!Spam!Spam!Spam!Spam!Spam!Spam!Spam!Spam!Spam!

<module 'sgapr08' from 'C:\Python25\sgapr08.pyc'>
>>> 
>>> pathname = 'email.Message'
>>> module = __import__(pathname)
>>> module
<module 'email' from 'C:\Python25\lib\email\__init__.pyc'>
>>> dir(module)
['Charset', 'Encoders', 'Errors', 'FeedParser', 'Generator', 'Header', 'Iterators', 'LazyImporter', 'MIMEAudio', 'MIMEBase', 'MIMEImage', 'MIMEMessage', 'MIMEMultipart', 'MIMENonMultipart', 'MIMEText', 'Message', 'Parser', 'Utils', '_LOWERNAMES', '_MIMENAMES', '__all__', '__builtins__', '__doc__', '__file__', '__name__', '__path__', '__version__', '_name', 'base64MIME', 'email', 'importer', 'message_from_file', 'message_from_string', 'mime', 'quopriMIME', 'sys']
>>> ================================ RESTART ================================
>>> 
1
aa
>>> ================================ RESTART ================================
>>> 
0
aa
>>> ================================ RESTART ================================
>>> 
I am: __main__
0
aa
>>> 
>>> import min
I am: min
>>> min.min(20, 70, 10)
10
>>> fname = 'README.txt'
>>> 
>>> len( open(fname).read() )
55400
>>> len( open(fname).readlines() )
1291
>>> 
>>> tot = 0
>>> for line in open(fname): tot += 1

>>> tot
1291
>>> 
>>> tot = 0
>>> for line in open(fname): tot += len(line)

>>> tot
55400
>>> 
>>> def countChars(filename):
	return len( open(filename).read() )

>>> countChars('README.txt')
55400
>>> 
>>> countChars(raw_input('File?'))
File?sgapr08.py
120
>>> 

>>> ================================ RESTART ================================
>>> 
Bob Smith 100000
>>> name = 'Bob Smith'
>>> name.split()
['Bob', 'Smith']
>>> name.split()[-1]
'Smith'
>>> ================================ RESTART ================================
>>> 
Bob Smith 100000
Smith
110000.0
>>> ================================ RESTART ================================
>>> 
Bob Smith 100000
Smith Jones
110000.0
>>> ================================ RESTART ================================
>>> 
Bob Smith 100000
Smith Jones
<__main__.People instance at 0x00BB2530>
>>> ================================ RESTART ================================
>>> 
[Person: Bob Smith, 0]
[Person: Sue Jones, 100000]
Smith Jones
[Person: Sue Jones, 110000.0]
>>> ================================ RESTART ================================
>>> 
[Person: Bob Smith, 0]
[Person: Sue Jones, 100000]
Smith Jones
[Person: Sue Jones, 110000.0]
[Person: Tom Jones, 60000.0]
>>> ================================ RESTART ================================
>>> 
>>> 
>>> import shelve
>>> db = shelve.open('sgapr08db')
>>> x = db['bob']
>>> print x
[Person: Bob Smith, 0]
>>> 
>>> print db['sue']
[Person: Sue Jones, 100000]
>>> 
>>> db.keys()
['tom', 'bob', 'sue']
>>> 
>>> len(db)
3
>>> 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]
>>> 
>>> dir('spam')
['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__str__', 'capitalize', 'center', 'count', 'decode', 'encode', 'endswith', 'expandtabs', 'find', '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']
>>> 
>>> class mystr(str):
	def __add__(...):
KeyboardInterrupt
>>> 
>>> 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!
>>> 
>>> 
