简体   繁体   English

如何修复并非所有在字符串格式化期间转换的参数?

[英]How can I fix not all arguments converted during string formatting?

I want to change some binary streams to decimal but I got not all arguments converted during string formatting .我想将一些二进制流更改为十进制,但在字符串格式化期间并未转换所有参数 The point is I have the result when using binaryToDecimal (10100000) which 10100000 is the first value of my list.关键是我在使用binaryToDecimal (10100000)时得到了结果,其中10100000是我列表的第一个值。 But when I use binaryToDecimal (instream_chunks[0]) which is my for loop I got the above error.但是当我使用binaryToDecimal (instream_chunks[0])这是我的for循环时,我得到了上述错误。 How can I fix that?我该如何解决? I am new to python sorry for my simple question.......我是 python 新手,抱歉我的简单问题......

def binaryToDecimal(binary):
      
    binary1 = binary
    decimal, i, n = 0, 0, 0
    while(binary != 0):
        dec = binary % 10
        decimal = decimal + dec * pow(2, i)
        binary = binary//10
        i += 1
    print(decimal)
    
    instream = '1010000000011000000110000000001'

    instream_chunks = [instream[i:i+8]for i in range (0, len(instream), 8)]

for i in range (len(instream_chunks)):
    
     img_value = binaryToDecimal (instream_chunks[i])

You need to convert the strings to integers before using your function on them.在对它们使用函数之前,您需要将字符串转换为整数。 Like so:像这样:

def binaryToDecimal(binary):
      
    binary1 = binary
    decimal, i, n = 0, 0, 0
    while(binary != 0):
        dec = binary % 10
        decimal = decimal + dec * pow(2, i)
        binary = binary//10
        i += 1
    print(decimal)
    
instream = '1010000000011000000110000000001'

instream_chunks = [instream[i:i+8]for i in range (0, len(instream), 8)]

for i in range (len(instream_chunks)):
     img_value = binaryToDecimal (int(instream_chunks[i]))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何修复 TypeError:并非所有参数都在字符串格式化期间转换 - How to fix TypeError: not all arguments converted during string formatting 如何修复 Python 中的“TypeError:并非所有参数都在字符串格式化期间转换” - How to fix 'TypeError: not all arguments converted during string formatting' in Python 如何修复它我收到类型错误,并非所有参数都在字符串格式化期间转换 - how to fix it i get type error, not all arguments converted during string formatting 类型错误:并非所有参数都在字符串格式化期间转换。 有关如何解决此问题的任何帮助? - TypeError: not all arguments converted during string formatting. Any help on how to fix this? 我收到TypeError:并非在格式化字符串时转换了所有参数 - I am getting a TypeError: Not all arguments converted during string formatting TypeError: not all arguments 在字符串格式化期间转换,我有这个错误 - TypeError: not all arguments converted during string formatting, I have this error Flask,并非在字符串格式化期间转换所有参数 - Flask, not all arguments converted during string formatting ProgrammingError:并非所有参数都在字符串格式化期间转换 - ProgrammingError: not all arguments converted during string formatting 并非在字符串格式化python期间转换了所有参数 - not all arguments converted during string formatting python postgres:并非在格式化字符串时转换所有参数 - postgres: not all arguments converted during string formatting
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM