How can an int be '+' with a tuple?
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Sun Jun 3 00:59:34 EDT 2018
On Sun, 03 Jun 2018 10:55:04 +0800, Jach Fong wrote:
> The attached is a script which can run under Python 3.4/Windows Vista
> correctly. One thing make me puzzled is that the "any + context" at line
> 18. The "any" was passed as an integer from line 43 and the "context"
> was defined as a tuple at line 35. This concatenation works! how?
90% of the script you attached is irrelevant to your question. None of
the tkinter or threading code is important. The only important parts are:
def threaded(action, args, context, onExit, onProgress):
def progress(*any):
threadQueue.put((onProgress, any + context))
Here we can tell that ``any`` is a tuple. But what is context? Following
it backwards, we find:
context = (myname,),
which is not an int, but a tuple. Try it for yourself:
py> value = ("Steven",),
py> print(value)
(('Steven',),)
--
Steven D'Aprano
"Ever since I learned about confirmation bias, I've been seeing
it everywhere." -- Jon Ronson
More information about the Python-list
mailing list