2

I get an error when I try to do a simple typecasting from string to integer in python (2.7):

year = device.time[year_pos:].strip() # This is '1993'
t = int(year) # Throws exception: "UnboundLocalError: local variable 'int' referenced before assignment"

Why? :)

1 Answer 1

2

The UnboundLocalError sounds as if you've assigned something to the name int in some other scope in your code (i.e., the code throwing the exception is inside a function, and you've used int as a name to store a variable in global code, or somewhere else). There's a blog post about UnboundLocalError where you can read more about this kind of problem, but for your issue, I'd just recommend not using builtin names to store variables.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.