打开一个文件,读取二进制到字符和字符到二进制。不起作用

2024-09-29 23:21:33 发布

您现在位置:Python中文网/ 问答频道 /正文

def main():
    choice=raw_input("To convery from binary to words press w, to convery from words to binary press b: ")
    theFile = open(raw_input("Enter File Name"),"rb")
    if choice=="w":
        ''.join(chr(int(theFile[i:i+8], 2)) for i in xrange(0, len(theFile), 8))
    if choice=="b":
        ' '.join(format(ord(x), 'b') for x in theFile)
main()

好吧,我有个错误。我不相信我读了正确的文件,并给出了正确的信息,我的两个如果语句。 二进制= 1001000 1100101 1101100 1101100 1101111 101100 100000 1010111 1101111 1110010 1101100 1100100 0100001 文本= 你好,世界

希望用户输入这两个文件中的一个


Tags: toinfromforinputrawifmain

热门问题