Newbie Question

John Roth johnroth at ameritech.net
Sun Oct 7 11:20:43 EDT 2001


"Mel Brown" <mel.b at mindspring.com> wrote in message
news:9pp1ca$ca6$1 at slb4.atl.mindspring.net...
> I am trying to get Python up and running. Among the modules that I know
that
> I will need are math, cmath, and string.
>
> When I import sys, then print out the included module names, I get that
math
> and cmath are included but sting is not. When I import math and then try
to
> compute something simple like sin(3), I am told that the function sin() is
> not available.
>
> My question is how to make the modules math, cmath, and string available
for
> my use.

import math
x = math.sin(y)

Notice that the math. is needed because the form of the import statement
doesn't put the functions into the namespace.

from math import sin
x = sin(y)

This allows you to get by without the qualification, but there are other
reasons
why you might not want to do it that way.

As far as string goes, it's usually better to use the string methods rather
than
the string module.

John Roth







More information about the Python-list mailing list