Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 3rd, 2005, 8:01 PM   #1
arod199113
Programmer
 
arod199113's Avatar
 
Join Date: Feb 2005
Posts: 86
Rep Power: 0 arod199113 is an unknown quantity at this point
Talking 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 is offline   Reply With Quote
Old Feb 3rd, 2005, 9:22 PM   #2
arod199113
Programmer
 
arod199113's Avatar
 
Join Date: Feb 2005
Posts: 86
Rep Power: 0 arod199113 is an unknown quantity at this point
Talking

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 is offline   Reply With Quote
Old Feb 4th, 2005, 9:24 PM   #3
arod199113
Programmer
 
arod199113's Avatar
 
Join Date: Feb 2005
Posts: 86
Rep Power: 0 arod199113 is an unknown quantity at this point
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 is offline   Reply With Quote
Old Feb 5th, 2005, 8:40 AM   #4
arod199113
Programmer
 
arod199113's Avatar
 
Join Date: Feb 2005
Posts: 86
Rep Power: 0 arod199113 is an unknown quantity at this point
i have python 2.0 if that helps
arod199113 is offline   Reply With Quote
Old Feb 5th, 2005, 8:50 AM   #5
Dizzutch
Professional Programmer
 
Dizzutch's Avatar
 
Join Date: Dec 2004
Location: Worcester, MA
Posts: 441
Rep Power: 4 Dizzutch is on a distinguished road
Send a message via ICQ to Dizzutch Send a message via AIM to Dizzutch Send a message via MSN to Dizzutch Send a message via Yahoo to Dizzutch
it turns orange becuase your text editor support syntax highlighting. import just imports a different package, so you can use functions from those packages.
__________________
naked pictures of you | PFO F@H stats
Dizzutch is offline   Reply With Quote
Old Feb 6th, 2005, 12:38 AM   #6
Dietrich
Professional Programmer
 
Dietrich's Avatar
 
Join Date: Feb 2005
Posts: 434
Rep Power: 4 Dietrich is on a distinguished road
Wink

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 *
Dietrich is offline   Reply With Quote
Old Feb 6th, 2005, 7:54 PM   #7
arod199113
Programmer
 
arod199113's Avatar
 
Join Date: Feb 2005
Posts: 86
Rep Power: 0 arod199113 is an unknown quantity at this point
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
arod199113 is offline   Reply With Quote
Old Feb 7th, 2005, 4:27 PM   #8
thechristelegacy
Expert Programmer
 
thechristelegacy's Avatar
 
Join Date: Jul 2004
Location: Somerset, Pa
Posts: 707
Rep Power: 4 thechristelegacy is on a distinguished road
Send a message via AIM to thechristelegacy Send a message via MSN to thechristelegacy
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.
thechristelegacy is offline   Reply With Quote
Old Feb 9th, 2005, 6:43 PM   #9
arod199113
Programmer
 
arod199113's Avatar
 
Join Date: Feb 2005
Posts: 86
Rep Power: 0 arod199113 is an unknown quantity at this point
Question

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
arod199113 is offline   Reply With Quote
Old Feb 10th, 2005, 10:17 AM   #10
Dietrich
Professional Programmer
 
Dietrich's Avatar
 
Join Date: Feb 2005
Posts: 434
Rep Power: 4 Dietrich is on a distinguished road
Smile

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.
Dietrich is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:35 AM.

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