I am trying to generate a random three digit extension:
>>> ''.join(str(x) for x in random.sample(range(1,10),3))
It works in the prompt. However, when I run the program, it raises a TypeError: str object is not callable. This is the line that I have:
filename = hashlib.md5(imagefile.getvalue()).hexdigest() +
''.join(str(x) for x in random.sample(range(1,10),3)) + '_thumb' + '.jpg'
What am I doing wrong here and how would I fix it?
Thank you for the help. I had invoked str previously in the code, which was causing the error:
str=""
for c in i.chunks():
str += c
...
I’ve tried it out both in the console and calling it in a .py file and both work.
Are you sure you’re not declaring a variable called “str” somewhere in your code before that invocation?
This works:
This:
Give the same error you’re reporting.