First page Back Continue Last page

Python Overview


Notes:

clean
    not an evolution from shell/awk like Perl
    consistent use of type throughout language/libraries

interpreted
    interactive
    introspection

types
    strong =>  each object has type (c/c++ have void* etc.)
    dynamic => not done at compile time
        def add(var1,var2):
            print var1+var2
        add(1,1)
        add("1","1")
        "1"+1
        int("1")+1
    high level
        l=[1,"1",[add,dir]]
            l[0:2]
            l[-1][0](1)
            "  1 2  3 4   ".strip()
            "  1 2  3 4   ".strip().split()
            for number in "  1 2  3 4   ".strip().split():
                print number**2
        d={1:"one",2:"two"}
            d[3]="three"
            d[3]=[1,2,3]

default library
    see /usr/lib/python2.2
    import os, re
        rec=re.compile("^[g-k]")
        files = filter(rec.match, os.listdir("/bin/"))
        def filesizes(files):
            file_size_map={}
            for file in files:
                file_size_map[file]=os.stat("/bin/"+file).st_size
            return file_size_map
    import locale
        locale.setlocale(locale.LC_ALL,"")
        def print_file_sizes(file_sizes):
            for file in file_sizes:
                print "%.7s\t%s" % (file,locale.format("%d", file_sizes[file], 1))
        locale.setlocale(locale.LC_ALL,"de_DE")
        locale.setlocale(locale.LC_ALL,"fr_FR")
        LANG=el_GR gedit
        LANG=ga_IE ./FSlint
    import gtk
        more later

extend/embed
    openoffice = embed
    modules    = extend