~/home_Python/apple_/Ascii/ascii.py
|INDEX| Python.use(better)
》作業中です《
#! /usr/bin/env python # coding: utf-8 ## ---------------------------------------- ## ## (C) Copyright 2000-2010, 小粒ちゃん《監修》小泉ひよ子とタマゴ倶楽部 ## ## ---------------------------------------- # ..+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8 """ >>> None >>> ## ---------------------------------------- >>> None version: #1.0.36 """ ## ---------------------------------------- def step00(): """class ASCII(object):""" class ASCII(object): pass ## ---------------------------------------- def ex_ascii(local): #@: source = ''' a = ASCII(); a '''.split("\n") do_it(source, local) ## ---------------------------------------- local = locals() ex_ascii(local) ## ---------------------------------------- def step01(): """def __init__(self):""" class ASCII(object): def __init__(self): self.cset = [] def __repr__(self): return "".join(self.cset) ## ---------------------------------------- local = locals() ex_ascii(local) ## ---------------------------------------- def step02(): """def _cset(self):""" class ASCII(object): def __init__(self): self.cset = self._cset() def _cset(self): s = [] start,stop = "@","Z" for e in range(ord(start), ord(stop)+1): s.append(chr(e)) return s def __iter__(self): for e in self.cset: yield e def __repr__(self): return "".join(self) ## ---------------------------------------- local = locals() ex_ascii(local) ## ---------------------------------------- def step03(): """[chr(e) for e in ...]""" class ASCII(object): def __init__(self): self.cset = self._cset() def _cset(self): start,stop = "@Z" s = ord(start), ord(stop)+1 return [chr(e) for e in range(*s)] def __iter__(self): for e in self.cset: yield e def __repr__(self): return "".join(self) ## ---------------------------------------- local = locals() ex_ascii(local) ## ---------------------------------------- def step04(): """def _body(self):""" class ASCII(object): def __init__(self): self.cset = self._cset() def _cset(self): start,stop = "0Z" s = ord(start), ord(stop)+1 return [chr(e) for e in range(*s)] def __iter__(self): for e in self.cset: yield e def __repr__(self): s = self._body() return "".join(s) def _body(self): s = [] for i,e in enumerate(self): c = " " if not (i+1)%16: c = "\n" s.append(e+c) return s ## ---------------------------------------- local = locals() ex_ascii(local) ## ---------------------------------------- def step05(): """c = " \\n"[not (i+1)%16]""" class ASCII(object): def __init__(self): self.cset = self._cset() def _cset(self): (start,stop),d = "0Z",6 s = ord(start), ord(stop)+d return [chr(e) for e in range(*s)] def __iter__(self): for e in self.cset: yield e def __repr__(self): s = self._body() return "".join(s) def _body(self): s = [] for i,e in enumerate(self): c = " \n"[not (i+1)%16] s.append(e+c) return s ## ---------------------------------------- local = locals() ex_ascii(local) ## ---------------------------------------- def step06(): """[e+" \\n"[not (i+1)%16]""" class ASCII(object): def __init__(self): self.cset = self._cset() def _cset(self): (start,stop),d = "0Z",6 s = ord(start), ord(stop)+d return [chr(e) for e in range(*s)] def __iter__(self): for e in self.cset: yield e def __repr__(self): s = self._body() return "".join(s) def _body(self): return [e+" \n"[not (i+1)%16] for i,e in enumerate(self)] ## ---------------------------------------- local = locals() ex_ascii(local) ## ---------------------------------------- def step07(): """def _header(self):""" class ASCII(object): def __init__(self): self.cset = self._cset() def _cset(self): (start,stop),d = "0Z",6 s = ord(start), ord(stop)+d return [chr(e) for e in range(*s)] def __iter__(self): for e in self.cset: yield e def __repr__(self): s = self._header() s += self._line() s += self._body() return "".join(s) width,size = 31,16 def _body(self): return [e+" \n"[not (i+1)%self.size] for i,e in enumerate(self)] def _header(self): s = ["%X"%e for e in range(self.size)] return ["%s\n"%" ".join(s)] def _line(self): return ["%s\n"%("-"*self.width)] ## ---------------------------------------- local = locals() ex_ascii(local) ## ---------------------------------------- def step08(): """def _title(self):""" class ASCII(object): def __init__(self): self.cset = self._cset() def _cset(self): (start,stop),d = " z",5 s = ord(start), ord(stop)+d return [chr(e) for e in range(*s)] def __iter__(self): for e in self.cset: yield e def __repr__(self): s = self._line("=") s += self._title() s += self._line("-") s += self._header() s += self._line("-") s += self._body() s += self._line("=") return "".join(s) width,size = 31,16 def _body(self): s = [e+" \n"[not (i+1)%self.size] for i,e in enumerate(self)] return ["%s\n"%"".join(s)] def _header(self): s = ["%X"%e for e in range(self.size)] return ["%s\n"%" ".join(s)] def _line(self, c): return ["%s\n"%(c*self.width)] def _title(self): t = "ASCII character set" return ["%s\n"%t.center(self.width)] ## ---------------------------------------- local = locals() ex_ascii(local) ## ---------------------------------------- def step09(): """def _body(self):""" class ASCII(object): def __init__(self): self.cset = self._cset() def _cset(self): (start,stop),d = " z",5 s = ord(start), ord(stop)+d return [chr(e) for e in range(*s)] def __iter__(self): for e in self.cset: yield e def __repr__(self): s = self._line("=") s += self._title() s += self._line("-") s += self._header() s += self._line("-") s += self._body() s += self._line("=") return "".join(s) width,size = 35,16 #### def _body(self): #### N = self.size #### s = [("","%s | "%("%x"%ord(e))[0])[not i%N]+e+" \n"[not (i+1)%N] #### for i,e in enumerate(self)] #### return ["%s\n"%"".join(s)] def _body(self): N = self.size s = [] for i,e in enumerate(self): x = ("%x"%ord(e))[0] s1 = ("","%s | "%x)[not i%N] s2 = " \n"[not (i+1)%N] s.append(s1+e+s2) return ["%s\n"%"".join(s)] def _header(self): s = ["%X"%e for e in range(self.size)] return [" | %s\n"%" ".join(s)] def _line(self, c): return ["%s\n"%(c*self.width)] def _title(self): t = "ASCII character set" return ["%s\n"%t.center(self.width)] ## ---------------------------------------- local = locals() ex_ascii(local) ## ---------------------------------------- ## ---------------------------------------- def ex_ascii(local): #@: source = ''' ASCII() '''.split("\n") do_it(source, local) ## ---------------------------------------- def do_it(source, local): for e in source[1:-1]: try: print_(e, local) except AttributeError as error: print("AttributeError:", error) except TypeError as error: print("TypeError:", error) ## ---------------------------------------- def print_(source, local, mode="single"): print(">>>",source) eval(compile(source,"",mode),globals(),local) ## ======================================== s = "step" DIR = [e for e in dir() if e.startswith(s)] DIR = dict((i,e) for i,e in enumerate(DIR)) DIR = list(DIR.items()); DIR.sort() def ex(): n = (len(DIR)-1)//10+1 for k,v in DIR: source = ''' x = eval("%%s.__doc__"%%v) print("%%%dd: %%s -- %%s"%%(k,v,x)) '''%n eval(compile(source,"","exec")) def do_all(): for k,v in DIR: do(k) def do(k=None): if k is None: ex(); return try: k,v = DIR[k] print(">>> #","-"*50,v) eval("%s()"%v) except IndexError: print("(x_x) too bad ... %s"%k) ## ---------------------------------------- from time import ctime def time_stamp(): print("="*24) print(ctime()) print("="*24) ## ---------------------------------------- from doctest import testmod if __name__=='__main__': time_stamp() testmod() ## ========================================
Last updated♪2010/03/13