加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python初学之helloworld

发布时间:2020-12-17 17:22:56 所属栏目:Python 来源:网络整理
导读:今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 '''print the "Hello,world!" on the console'''import os'''read data in file'''class File: def __init__(self): self.data = os.getcwd()+'data

以下代码由PHP站长网 52php.cn收集自互联网

现在PHP站长网小编把它分享给大家,仅供参考

'''
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')

以上内容由PHP站长网【52php.cn】收集整理供大家参考研究

如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读