python">'''
print the "Hello, world!" on the console
'''
import os
'''
read data in file
'''
class File:
def __init__(self):
self.data = os.getcwd()+'\\data.txt'
self.datalines = self.readDataToList()
def readDataToList(self):
data = []
try:
file = open(self.data,"r")
data = file.readlines()
finally:
file.close()
return data
def getDataAtIndex(self,num):
return self.datalines[num]
def getData(self,nList):
dataList = []
for i in nList:
dataList.append(self.getDataAtIndex(i))
return dataList
'''
get char index
'''
class Index:
def getIndexList(str):
indexList = []
for x in list(str):
indexList.append(ord(x)-0x20)
return indexList
'''
print content
'''
class MyPrint:
'''
def myPrint(self,tup):
for i in tup:
forPrint = ''
for j in range(8):
if int(i,16)&(0x01<<j):
#make every '1' into '*'
forPrint = '*' + forPrint
else:
forPrint = ' ' + forPrint
print(forPrint)
'''
def getSingleByte(self,str16):
sByte = ''
for i in range(8):
if int(str16,16)&(0x01<<i):
sByte = '*' + sByte
else:
sByte = ' ' + sByte
return sByte
def concatOneLine(self,matrix,lineNum):
sLine = ''
for data in matrix:
sLine+=self.getSingleByte(data[lineNum])
return sLine
def printInLine(self,matrix):
som = len(matrix)
printLine = ''
for i in range(len(matrix[0])):
printLine+=self.concatOneLine(matrix,i)+'\n'
print(printLine)
'''
main
'''
if __name__=='__main__':
content = input('输入你想打印的内容(只限ASCII码可表示的内容——英文、数字和部分符号):\n')
indexList = Index.getIndexList(content)
file = File()
matrix = []
for i in indexList:
data = file.getDataAtIndex(i)
matrix.append(data.split(','))
myPrint = MyPrint()
myPrint.printInLine(matrix)
os.system('pause')
标签:python