Python Library Question

Jeff Shannon jeff at ccvcorp.com
Wed Aug 22 21:21:41 CEST 2001


Kurt Jansen wrote:

> I am new to Python, and am trying to implement a Web site using Python
> for my CGI scripts.  I am having trouble using any of the functions in
> the Python Library on my Web hosting provider's system.  For instance,
> if I try to use the math functions, I get the following errors:
> west38:~$ python
> Python 1.4 (Dec 18 1996) [GCC 2.7.2.1]
> Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
> >>> import math
> >>> x=2
> >>> y=exp(x)
> Traceback (innermost last):
> File "<stdin>", line 1, in ?
> NameError: exp
> >>>
>
> Am I doing something wrong, or is the Python Library not loaded on my
> hosting provider's system?
> Kurt Jansen

When you are using functions (or other attributes) from an imported
module, you have to prepend the module name--in effect, you're telling the
interpreter *where* to find that function.  So try:

>>> import math
>>> x = 2
>>> y = math.exp(2)
>>> y
7.3890560989306504


Jeff Shannon
Technician/Programmer
Credit International





More information about the Python-list mailing list