GT96 GT96 - 1 year ago 84
Python Question

Python: AttributeError: 'int' object has no attribute 'final_stat

I am stuck in a program. I can't post only the part of the code with error because it is dependent on the rest of the code. So, I have posted the complete code in the link below. Just look at like no. 113 and 114. When I am using

fs = fsa.final_state
it is giving me the error:
AttributeError: 'int' object has no attribute 'final_state'
. However, I am able to use
print("TEST", fsa.final_state)
without any error and the output is also correct. Please ask any part of the code you don’t understand. Thanks.


Answer Source

I've looked through your code. On this line here:

print("'%s'\t%s" % (input, NDRecognize(input, days)))

Your passing the parameter days to NDRecognize. But when I do print(type(days)) I get int. However the days parameter is passed through toloop() and then accept_state() as fsa until you try to access one of it's properties, where the error occurs.

In short, your passing an int as fsa, not an actual FSA object. You'll have to create it and then pass that through as a parameter.


Around line 260 you write days = 31 which overrides the days declaration from earlier in the program on line 72. You don't redefine months however, which is why it works for months but not for days

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download