472,965 Members | 2,522 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,965 software developers and data experts.

Learning Python : >>> import math doesn't work ?

Have carefully installed Python 2.5.1 under XP in dir E:\python25 .
ran set path = %path% ; E:\python25
Python interactive mode works fine for simple arithmetic .
Then tried >> import math
>> x = sqrt(100)
Get error Name error : name 'sqrt' is not defined
Same thing with sin(x) .
I'm unable to find "math" , "sqrt" , or "sin" anywhere in lib , Libs
or include directories .
The Tutorial does not clear this up .
Please help. Thanks Dave pd******@earthlink.net
Nov 19 '07 #1
4 21968
On Nov 18, 8:48 pm, pdlem...@earthlink.net wrote:
Have carefully installed Python 2.5.1 under XP in dir E:\python25 .
ran set path = %path% ; E:\python25
Python interactive mode works fine for simple arithmetic .
Then tried >> import math
>> x = sqrt(100)
Get error Name error : name 'sqrt' is not defined
Same thing with sin(x) .
I'm unable to find "math" , "sqrt" , or "sin" anywhere in lib , Libs
or include directories .
The Tutorial does not clear this up .
Please help. Thanks Dave pdlem...@earthlink.net
Hi,

I believe that should be:
x = math.sqrt(100)

'import math' makes available the functions in the math module, but
they are still inside the math namespace, so still require 'math.'
If you will be using sqrt a lot, you can create a copy of the function
in the local namespace using
sqrt = math.sqrt
x = sqrt(100)

[In principle, you can give it any name you want, but of course it is
sensible to use a name that makes sense.
E.g. if you were a Spanish speaker, you could say instead
raiz = math.sqrt
x = raiz(100)
]

For more details about how 'import'ing works, check out the Python
tutorial.

Hope that helps.
Best wishes,

David.


Nov 19 '07 #2
On Nov 19, 10:48 am, pdlem...@earthlink.net wrote:
Have carefully installed Python 2.5.1 under XP in dir E:\python25 .
ran set path = %path% ; E:\python25
Python interactive mode works fine for simple arithmetic .
Then tried >> import math
>> x = sqrt(100)
Get error Name error : name 'sqrt' is not defined
Same thing with sin(x) .
I'm unable to find "math" , "sqrt" , or "sin" anywhere in lib , Libs
or include directories .
The Tutorial does not clear this up .
Please help. Thanks Dave pdlem...@earthlink.net
use it like: x = math.sqrt (100) and math.sin(x)
Nov 19 '07 #3
On Nov 19, 3:46 pm, windspy <wind...@gmail.comwrote:
use it like: x = math.sqrt (100) and math.sin(x)
alternatively import like this:

from math import sqrt, sin

.... and use it like you have.

Nov 19 '07 #4

"Asun Friere" <af*****@yahoo.co.ukwrote in message
news:86**********************************@s36g2000 prg.googlegroups.com...
| On Nov 19, 3:46 pm, windspy <wind...@gmail.comwrote:
| use it like: x = math.sqrt (100) and math.sin(x)
|
| alternatively import like this:
|
| from math import sqrt, sin
|
| ... and use it like you have.

Or,
import math as m # to save typing, especially in interactive mode
x = m.sin(1) #etc

Nov 19 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Thomas Brathans | last post by:
Hi, when I try to execute the obove mentioned to synchronise the servertime by a php-script, it doesn't work. Other shell-commands work fine. Executing ntpdate <server> directly in the shell...
4
by: edg | last post by:
This works: $b = $a->method1(); $c = $b->method2(); I'd like to get this all on one expression, something like: $c = ${$a->method1()}->method2(); which doesn't work.
3
by: Paul Thompson | last post by:
When I put a <div ...> inside a <table> specification, functionality is not there. When I put the <table> inside the <div> everything works. Why is that?
2
by: beetle | last post by:
Hello, I'm storing data in several different binary tree's. The root node is located in a struct containing general data about the tree. struct lnode { char *fname; int nentry;
1
by: Alex VanderWoude | last post by:
I am trying to <include> some text into an XML documentation topic, but that text is stored in a file that is in a different directory than the "current" XML file. Using a relative path does not...
2
by: Maureen | last post by:
Hi: Our ASP.NET webapplication works on our development webserver, but fails on our production webserver - I cannot get any detailed error information: -It is an application -Mode in...
1
by: Alex Chun | last post by:
I have an Access database -- a .mdb file -- on a server on our network. When the file is in use -- i.e. there is an associated .ldb file -- I cannot open the database by double-clicking its icon;...
6
by: Stef Mientki | last post by:
hello, I want to find all files with the extension "*.txt". From the examples in "Learning Python, Lutz and Asher" and from the website I see examples where you also may specify a wildcard...
1
by: DukeRev | last post by:
I made a box where if you hover over the DIV tag it changes the color of the link text. It works in firefox and opera, but it doesn't work in IE. Doesn't anyone know why it doesn't work and how to...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.