why don't my global variables get initialized?

Skip Montanaro skip at mojam.com
Tue Feb 15 18:36:35 CET 2000


    Nathan> However, this doesn't seem to be working, because none of those
    Nathan> three global variables are initialized after I call the
    Nathan> function:

    Nathan> Python 1.5.2 (#1, Jul 22 1999, 11:59:40)  [GCC 2.8.1] on sunos5
    Nathan> Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
    >>>> from genetics import *
    >>>> init_global_data('att48.tsp')
    >>>> num_cities
    Nathan> 0
    >>>> citylist
    Nathan> []
    >>>> matrix
    Nathan> []

    Nathan> Those are the default values those variables started out with.

All you've done is create new names that reference the initial values.  The
values in the module were updated, but the names in the current scope were
still referencing the old values.  Try the following instead:

    impor genetics
    genetics.init_global_data('att48.tsp')
    print genetics.num_cities
    print genetics.citylist
    print genetics.matrix

from-module-import-*-strikes-again-ly y'rs,

Skip Montanaro | http://www.mojam.com/
skip at mojam.com | http://www.musi-cal.com/
"Languages that change by catering to the tastes of non-users tend not to do
so well." - Doug Landauer





More information about the Python-list mailing list