python初学之helloworld
- 作者: 铁掌奶上嫖
- 来源: 51数据库
- 2022-08-12
'''
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')
推荐阅读
热点文章
Discord.py(重写)on_member_update 无法正常工作
0
Discord.py 在 vc 中获取用户分钟数
0
discord.py 重写 |为我的命令出错
0
Discord.py rewrite 如何 DM 命令?
0
播放音频时,最后一部分被切断.如何解决这个问题?(discord.py)
0
在消息删除消息 Discord.py
0
如何使 discord.py 机器人私人/直接消息不是作者的人?
0
(Discord.py) 如何获取整个嵌入内容?
0
Discord bot 尽管获得了许可,但不能提及所有人
0
Discord.py discord.NotFound 异常
0
