Can global variable be passed into Python function?
steve+comp.lang.python at pearwood.info
Sat Feb 22 07:29:58 CET 2014
On Fri, 21 Feb 2014 22:45:14 -0500, Ned Batchelder wrote:
> I think it might be that the OP's question, "Can a global variable be
> passed into a function", really had nothing to do with the
> name/value/variable distinction, and we've done it again: taken a simple
> question and spun off into pedantry and trivia.
You might be right, but the OP's question isn't really clear. Surely he
didn't mean something as trivial as this?
x = 1 # This is a global
some_function(x) # Passing a global into a function
His description, especially the comment about pass by reference, suggests
that there is more to it than just passing a global variable as argument
to a function. I think he is trying to *write* to the variable as well,
as an output variable, something like this:
x = 1
y = 2
assert x == 99
assert y == 99
Sadly, it appears to have been a drive-by question: Sam tossed a question
out the window as he drove by, and may never come back for the answer...
I hope I'm wrong, but it's been nearly 24 hours since the question was
asked and not a peep from the OP.
Sam, if you're out there reading this, please respond with more detail
about what you are trying to do!
More information about the Python-list