Question

I have a very frustrating python problem. In this code

fixedKeyStringInAVar = "SomeKey"

def myFunc(a, b):
    global sleepTime
    global fixedKeyStringInAVar
    varMe=int("15")
    sleepTime[fixedKeyStringInAVar] = varMe*60*1000
    #more code

Now this works. BUT sometimes when I run this function I get

TypeError: 'int' object does not support item assignment

It is extremely annoying since I tried several test cases and could not reproduce the error, yet it happens very often when I run the full code. The code reads data from a db, access sites, etc. so its hard for me to go through the data since it reads from several sources and depends on 3rd party input that changes (websites).

What could this error be?

Was it helpful?

Solution

  1. Don't use global keyword in a function unless you'd like to change binding of a global name.

  2. Search for 'sleepTime =' in your code. You are binding an int object to the sleepTime name at some point in your program.

OTHER TIPS

Your sleepTime is a global variable. It could be changed to be an int at some point in your program.

The item assignment is the "foo[bar] = baz" construction in your function.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top