代码之家  ›  专栏  ›  技术社区  ›  olg32

在Python中打印扩展ASCII字符

  •  5
  • olg32  · 技术社区  · 7 年前

    我想用Python创建具有以下ascii字符的菜单框:

    ASCII码200=(方框图字符双线左下角)

    ASCII代码202=(方框图字符双线水平和向上)

    ASCII码203=(方框图字符双线水平向下)

    ASCII代码205=(方框图字符双水平线)

    ASCII码206=(方框图字符双线水平垂直)

    非常感谢。

    2 回复  |  直到 7 年前
        1
  •  7
  •   chickity china chinese chicken    7 年前

    它似乎适用于字符串文字:

    >>> symbs = [u'\u255a', u'\u2554', u'\u2569', u'\u2566', u'\u2560', u'\u2550', u'\u256c']
    >>> for sym in symbs:
    ...     print(sym)
    ... 
    ╚
    ╔
    ╩
    ╦
    ╠
    ═
    ╬
    

    代码来自 http://svn.python.org/projects/stackless/trunk/Lib/encodings/cp720.py

    希望这有帮助。

        2
  •  3
  •   Community CDub    5 年前

    class TableBorder:
        def __init__ (self, top_left, top_split, top_right,
            mid_left, mid_split, mid_right,
            low_left, low_split, low_right,
            horizontal, vertical):
            self.top_left = top_left
            self.top_split = top_split
            self.top_right = top_right
            self.mid_left = mid_left
            self.mid_split = mid_split
            self.mid_right = mid_right
            self.low_left = low_left
            self.low_split = low_split
            self.low_right = low_right
            self.horizontal = horizontal
            self.vertical = vertical
    
    Borders0 = TableBorder ('+', '+', '+', '+', '+', '+', '+', '+', '+', '-', '|')
    Borders1 = TableBorder (u'\u250c',u'\u252C',u'\u2510',u'\u251C',u'\u253C',u'\u2524',u'\u2514',u'\u2534',u'\u2518',u'\u2500',u'\u2502')
    Borders2 = TableBorder (u'\u2554',u'\u2566',u'\u2557',u'\u2560',u'\u256C',u'\u2563',u'\u255a',u'\u2569',u'\u255d',u'\u2550',u'\u2551')
    
    def draw_box (width, height, box):
        span = width-2
        line = box.horizontal * (span)
        print (box.top_left + line + box.top_right)
        body = box.vertical + (' '*span) + box.vertical
        for _ in range (height-1):
            print (body)
        print (box.low_left + line + box.low_right)
    
    draw_box (20, 10, Borders1)