2014年5月24日土曜日

開発環境

Head First Python (Paul Barry(著)、 O'Reilly Media; )のChapter 2(Sharing your Code: Modules of functions)、Sharpen your pencil(p.37)を解いてみる。

Sharpen your pencil(p.37)

コード(BBEdit)

nester.py

#!/usr/bin/env python3
#-*- coding: utf-8 -*-

"""
This is the nester.py module for nested (nested...) list.
function(s)
    printLoL(list)
"""

def printLoL(the_list):
    """
    print each data in the list( and nested list) print each line
    """
    for each_item in the_list:
        if isinstance(each_item, list):
            printLoL(each_item)
        else:
            print(each_item)

if __name__ == '__main__':
    movies = ["The Holy Grail", 1975, 'Terry Jones & Terry Gilliam', 91,
              ['Graham Chapman',
               ['Michael Palin', 'John Cleese', 'Terry Gillian', 'Eric Idle',
                'Terry Jones']]]
    printLoL(movies)

sample37.py

#!/usr/bin/env python3
#-*- coding: utf-8 -*-

import nester

print('{0:*<80s}'.format('dir(nester)'))
print(dir(nester))

for x in [nester, nester.printLoL]:
    print('{0:*<80s}'.format('help({0})'.format(x.__name__)))
    help(x)

入出力結果(Terminal)

$ ./sample37.py
dir(nester)*********************************************************************
['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'printLoL']
help(nester)********************************************************************
Help on module nester:

NAME
    nester

DESCRIPTION
    This is the nester.py module for nested (nested...) list.
    function(s)
        printLoL(list)

FUNCTIONS
    printLoL(the_list)
        print each data in the list( and nested list) print each line

FILE
    /Users/kamimura/Documents/py/hfpy/nester.py


help(printLoL)******************************************************************
Help on function printLoL in module nester:

printLoL(the_list)
    print each data in the list( and nested list) print each line

$ 

0 コメント:

コメントを投稿