Help on scope/namespace

Paul Rubin phr-n2003b at NOSPAMnightsong.com
Sun Feb 2 12:15:57 EST 2003


"Byron Morgan" <lazypointer at yahoo.com> writes:
> Is there some way I can import functions from a file, and have them behave
> just as though they are contained in the main script ?

Yes, just say "from file import function".  Or else prefix the function
name with the module name.

For example, you can start up Python and type:

  import math
  print math.sqrt(25)   # should print 5
  print sqrt(25)        # throws an exception since sqrt is not in namespace

Alternatively, you can type:

  from math import sqrt
  print sqrt(25)        # this will work now




More information about the Python-list mailing list