Imported globals?

Valentina Vaneeva fattie at
Fri Jul 27 17:05:48 CEST 2007


I'm new to Python and I've found something in its interpreter that I 
don't quite understand, and I don't really know how to correctly 
formulate a search query. Here's the question.

If we have a file with the following content:

|	#!/usr/bin/env python
|	value = 'initial'
|	def change_value():
|		global value
|		value = 'changed'

and a file

|	#!/usr/bin/env python
|	from module_a import value, change_value
|	change_value()
|	print value
Then, if we run, it will print "initial". However, if one 
adds to the end of this line:

|	change_value()

The script will print "changed".

It seems that in the first case change_value() called in 
ignores the global statement. Is it so? Why? What happens in the second 
case? I really don't get it.



More information about the Python-list mailing list