Skip to main content
 首页 » 编程设计

Python:使用 ascii 码打印

2025年05月04日16langtianya

我是 python 的初学者,我在这个程序中遇到了问题:

首先是 NodeList:

class Node: 
    def __init__(self,initdata): 
        self.data = initdata 
        self.next = None 
 
    def getData(self): 
        return self.data 
 
    def getNext(self): 
        return self.next 
 
    def setData(self,newdata): 
        self.data = newdata 
 
    def setNext(self,newnext): 
        self.next = newnext 

我的问题出在这个程序中:(打印)

from NodeList import Node 
 
class StackLL: 
 
    def __init__(self): 
        self.head = None 
 
    def pushSLL(self,item): 
        temp = Node(str(item)) 
        temp.setNext(self.head) 
        self.head = temp 
        node = self.head 
        print(chr(0x2510)+(chr(0x0000)*(len(item)))+chr(0x250c)) 
        while node!=None: 
            stackeditem = chr(0x2502)+node.data+chr(0x2502) 
            print(stackeditem) 
            node = node.next    
        print(chr(0x2514)+(chr(0x2500)*(len(item)-1))+chr(0x2518)) 

每次我打印时,线条似乎都消失了。我尝试使用 len() 进行实验只是为了使其准确,但每次该项目添加更多字符时它都会再次消失。任何帮助将不胜感激。谢谢。

请您参考如下方法:

在 IDLE 设置中使用等宽字体,一切都很好。