473,383 Members | 1,759 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Import...

58
What does import do?

Is it the same as copying the imported file into your new program?

for example:

Expand|Select|Wrap|Line Numbers
  1. import goodbyeworld
  2.  
  3. print "hello world"
  4.  
so helloworld.py would have all of goodbyeworld then all the rest of helloworld?
Mar 22 '07 #1
2 1009
ghostdog74
511 Expert 256MB
What does import do?

Is it the same as copying the imported file into your new program?

for example:

Expand|Select|Wrap|Line Numbers
  1. import goodbyeworld
  2.  
  3. print "hello world"
  4.  
so helloworld.py would have all of goodbyeworld then all the rest of helloworld?
don't quite get you. please read the docs here
Mar 22 '07 #2
bartonc
6,596 Expert 4TB
What does import do?

Is it the same as copying the imported file into your new program?

for example:

Expand|Select|Wrap|Line Numbers
  1. import goodbyeworld
  2.  
  3. print "hello world"
  4.  
so helloworld.py would have all of goodbyeworld then all the rest of helloworld?
Almost like that:
Expand|Select|Wrap|Line Numbers
  1. from helloworld import *
copies all the names (variables, function, classes, etc) into the namespace of the current module. So if you have module1:
Expand|Select|Wrap|Line Numbers
  1. # file module1.py
  2. def MyFucntion():
  3.     pass
and a second module, module2 imports it:
Expand|Select|Wrap|Line Numbers
  1. # file module2.py
  2. import module1 # import the module - actually runs the script
  3. module1.MyFunction() # call a function in an imported module
If you have commands or assignments in a module that you import, those commands and assignments get run just like every other part of the script (don't forget the def is just a command the creates a function). So if module1 has
Expand|Select|Wrap|Line Numbers
  1. print "hello world"
that will run when it is imported. I hope that's not too confusing.
Mar 24 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Stian Søiland | last post by:
all examples performed with: Python 2.3+ (#2, Aug 10 2003, 11:09:33) on linux2 (2, 3, 0, 'final', 1) This is a recursive import:
0
by: Vio | last post by:
Hi, I've been trying to embed (statically) wxPy alongside an embedded py interpreter on a linux/gtk box. At one point, for some reason misc.o linking reported "multiple definitions of...
0
by: John Roth | last post by:
I've found a case where it seems that Python is importing two copies of a module without any reason or indication. It took me a while to verify that this is what is occuring: I had to write a...
5
by: Steve Holden | last post by:
This is even stranger: it makes it if I import the module a second time: import dbimp as dbimp import sys if __name__ == "__main__": dbimp.install() #k = sys.modules.keys() #k.sort() #for...
1
by: mark | last post by:
In Access 2000 and 2002, I have created an import specification to import the fixed-width recordset below into an existing table. I am having strange problems with the import of the date and time...
4
by: Bruce W. Roeser | last post by:
All, I'm reading a book by Charles Petzold (Programming VS.Net). Pretty good content but am confused about the difference. From the text: ...
2
by: Jon | last post by:
It appears that (windows) python searches in the current working directory before looking in the local site-packages directory, or that '.' comes first in sys.path? The problem arises when I made...
7
by: Ron Adam | last post by:
from __future__ import absolute_import Is there a way to check if this is working? I get the same results with or without it. Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) on win 32 ...
5
by: W. Watson | last post by:
Is there a single source that explains these statements? ------------------------------ from Tkinter import * from Numeric import * import Image import ImageChops import ImageTk import time...
9
by: rsoh.woodhouse | last post by:
Hi, I'm trying to work out some strange (to me) behaviour that I see when running a python script in two different ways (I've inherited some code that needs to be maintained and integrated with...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.