在Python中,字符串作为整数读入?

在Python中,字符串作为整数读入?,python,string,input,integer,Python,String,Input,Integer,我正在编写一些代码,其中我读取了以下二进制数: 0000 0001 1000 1001 00000000 0000000 000000 00000 0000 部分代码读入输入,这样s=input()。然后调用函数accepts,该函数具有以下定义: def accepts(str_input): return accept_step(states[0], str_input, 0) # start in q0 at char 0 accept\u步骤功能定义为: def accep

我正在编写一些代码,其中我读取了以下二进制数:

0000
0001
1000
1001
00000000
0000000
000000
00000
0000
部分代码读入输入,这样
s=input()
。然后调用函数
accepts
,该函数具有以下定义:

def accepts(str_input):
    return accept_step(states[0], str_input, 0)  # start in q0 at char 0
accept\u步骤
功能定义为:

def accept_step(state, inp, pos):
    if pos == len(inp):  # if no more to read
        return state.is_final_state   # accept if the reached state is final state
    c = inp[pos]    # get char
    pos += 1
    try:
        nextStates = state.transitions[c]
    except():
        return False    # no transition, just reject

    # At this point, nextStates is an array of 0 or
    # more next states.  Try each move recursively;
    # if it leads to an accepting state return true.
    """
    *** Implement your recursive function here, it should read state in nextStates
    one by one, and run accept_step() again with different parameters ***
    """
    for state in nextStates:
        if accept_step(state, inp, pos): #If this returns true (recursive step)
            return True
    return False    # all moves fail, return false


"""
 Test whether the NFA accepts the string.
 @param in the String to test
 @return true if the NFA accepts on some path
"""
我得到这个错误:

    if pos == len(inp):  # if no more to read
TypeError: object of type 'int' has no len()
我已经尝试过使用
str(s)
(转换),例如在
input(str(s))
accepts(str(s))
中,但没有效果

不管出于什么原因,我的输入文本都是作为整数而不是字符串读取的


我希望以字符串而不是整数的形式读取输入,并能够使用字符串的
len()
属性来执行我的程序。请有人给我指出正确的方向,并向我解释为什么我的输入被读取为整数而不是字符串?我想如果我特别想要整数输入,我就必须使用类似于
int(input())

的东西,Python尝试假定输入的变量的类型。在这种情况下,它认为您正在输入整数。因此,请在赋值过程中围绕输入尝试str()

s = str(input())
accepts(s)
例如,Python3中的一些测试:

>>> a = 1001
>>> isinstance(a, int)
Returns: True

>>> b = '1001'
>>> isinstance(b, int)
Returns: False

>>> c = str(1001)

>>> isinstance(c, int)
Returns: False

>>> isinstance(c, str)
Returns: True

>>> len(c)
Returns: 4

我使用的是Python3.6.9,它以字符串类型接收二进制代码。