Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Python (http://www.programmingforums.org/forum43.html)
-   -   what is the import command? (http://www.programmingforums.org/showthread.php?t=2099)

arod199113 Feb 3rd, 2005 8:01 PM

what is the import command?
 
the tutorial i used never explain the "import" command
what does it do
does it import a .py file into the window?
so you dont have to type the whole program again


like say i have a program then at the bottom i type import whatever
when i go to edit\runscript it would run the first program then the imported one?
i have no clue




just tell me what the "import command does

arod199113 Feb 3rd, 2005 9:22 PM

im just correcting my grammar


like say i have a program then at the bottom i type import "apple"
when i go to edit\runscript would it run the first program then the imported program "apple" or no?
i have no clue

just tell me what the "import" command does

arod199113 Feb 4th, 2005 9:24 PM

ok
forget everythin i just said

when u type something like print,if,elif,else,and,while, and other stuff it turns orange i call those commands what u want to call them u can


when you type "import" in the "IDLE (GUI)" what does the import command do
it turns orange when i type import

arod199113 Feb 5th, 2005 8:40 AM

i have python 2.0 if that helps

Dizzutch Feb 5th, 2005 8:50 AM

it turns orange becuase your text editor support syntax highlighting. import just imports a different package, so you can use functions from those packages.

Dietrich Feb 6th, 2005 12:38 AM

There are several ways to use import, here is one example:
[php]
# math sqrt()

import math

print "\nSquare root of integer formatted as float with 4 decimals:"
for value in range(10):
squareRoot = math.sqrt(value)
print "sqrt(%d) = %.4f" % (value, squareRoot)
[/php]

The squareroot function is in module math. Notice how we used math.sqrt(value) to tie the two together. You can avoid the math prefix by using:
from math import sqrt
or if you use several other math functions:
from math import *

arod199113 Feb 6th, 2005 7:54 PM

Quote:

Originally Posted by Dietrich
There are several ways to use import, here is one example:
[php]
# math sqrt()

import math

print "\nSquare root of integer formatted as float with 4 decimals:"
for value in range(10):
squareRoot = math.sqrt(value)
print "sqrt(%d) = %.4f" % (value, squareRoot)
[/php]

The squareroot function is in module math. Notice how we used math.sqrt(value) to tie the two together. You can avoid the math prefix by using:
from math import sqrt
or if you use several other math functions:
from math import *



ok you cofused me on that
cause im jut a beginer
i guess i know y i havent learned the import just yet :o

thechristelegacy Feb 7th, 2005 4:27 PM

all import does is allow you to import other fucntions. like if you want to work with a lot of math functions such as finding the sqareroot, then you would use
:

import math
All it is doin't is importing a functions from modules.
I know it sounds like a lot, but it really isn't, it just expands the list of basic commands you have to work with.

arod199113 Feb 9th, 2005 6:43 PM

so if i was to type
import apple
it would make apple a command?
or only certain words
if it does import apple what would the command do

Dietrich Feb 10th, 2005 10:17 AM

Quote:

Originally Posted by arod199113
so if i was to type
import apple
it would make apple a command?
or only certain words
if it does import apple what would the command do

It would only work, if the Python file apple.py exists. If it had a function pie in it, you could call this function with apple.pie(dosomething) or whatever. Your Python installation already comes with a fair number of files you can import. You can download more functionality from various WEB sites like the wxPython stuff.


All times are GMT -5. The time now is 5:31 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC