Scope problem with nested functions.

AddisonN at AddisonN at
Wed Oct 12 18:33:00 CEST 2005

I'm having trouble resolving a scope problem. I have a module, called
from another script, with this structure:
def parseFile(file, myLocation, defaults):
     # initialisation.
     ccyMappings = {}
     def getCcyMappings()
          global ccyMappings
          # read values into ccyMappings.
          ccyMappings['CAN'] = ['CAD'] # for example.
    def mapCcy(myCcy):
        if ccyMappings.has_key(myCcy):
            return ccyMapping['myCcy']
            return myCcy   
My problem is that, although the ccyMappings dictionary is populated
within the def getCcyMappings() function, the value goes to 'None' when
I leave it and so is not available when the mapCcy function is called.
I've used the global scope declaration successfully before, but not with
nested functions like this, admittedly.
Any assistance gratefully received.

This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.
This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.
Information Technology International (ITI) +44 (0)20 7315 8500

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list