scoping questions

Mel Wilson mwilson at
Thu Jun 3 15:05:05 CEST 2004

In article <mailman.519.1086198524.6949.python-list at>,
"David Stockwell" <winexpert at> wrote:
>Another of my crazy questions.  I'm just in the process of learning so bear
>with me if you can.   I actually ran it....  with two test cases
>Say I have the following defined:
>--- beginning of code snippet ----
>def me(aFile):
>   """
>     Note I am testing scoping
>   """
>   aFile = 'hello world'
>   print aFile
>aFile = open('/tmp/test','r')
>data =
>print data

   Yet another way to think of it, since name spaces are
dictionary-like and we can "follow" the Python engine as it
runs through the subroutines:

things = {}
things['aFile'] = open ('/tmp/test/, 'r')

me_things = {}
me_things['aFile'] = things['aFile']
me_things['aFile'] = 'hello world'
print me_things['aFile']

things['data'] = things['aFile'].read()
print things['data']

   See how that works?  So in the next example, when you

me2_things['dog'] = things['aFile']

it's not really a surprise.

        Regards.        Mel.

More information about the Python-list mailing list