Newbie simple question - can't find answer

Preston Landers prestonlanders at my-deja.com
Tue Jan 11 11:36:05 EST 2000


In article <85fhha$6js$1 at nnrp1.deja.com>,
  eleisonme at juno.com wrote:

> I do not seem to be able to use any of the math or cmath functions
> either in a script or on the python command line.
>
> For example if I type:
> >>>import math
> >>>exp (4)

> I get a traceback error:
> NameError: exp (or any other math function that I try to use).

Greetings,

import by itself doesn't make a modules names visible in your current
namespace.  In other words, you have to put the module name in front of
the function you want to call.  This is so you can access identically
named things (functions) in different modules.

Basically, you want this:

>>> import math
>>> math.exp(4)
54.5981500331

There *is* a way to make all of a modules' names visible in the current
namespace.  However, it's generally not recommend (for the collision
reaons mentioned above.)

>>> from math import *
>>> exp(4)
54.5981500331

Read the tutorial section on namespaces for further clarification, or
feel free to ask here.

yours,

---Preston


--
|| Preston Landers <prestonlanders at my-deja.com> ||


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list