I found a very strange thing in Python. When trying to access an ordinary object (like int
, float
, etc.) from some function it's asking me to define the variable to be a global variable.
But when I tried to do the same with Queue
the result was different; in that situation I could approach the Queue
from the function even when I didn't make it global.
How can some objects act like globals (Queue
, for example) and some others not (like int
, string
, etc.)?
I clear myself: Here is two code samples: some def:
def some_def():
q.put(1)
some main:
q = Queue.Queue()
On the other object: some def:
def some_def():
number += 1
some main:
number = 0
The two different code samples will act each one different way: The first one will put the value in the Queue, while the second will throw an Error because 'number' is not a global variable.