By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,089 Members | 2,432 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,089 IT Pros & Developers. It's quick & easy.

import

P: 1
what is the difference between different importing options available in python

import time
from time import sleep
from time import *
Mar 24 '08 #1
Share this Question
Share on Google+
1 Reply


bvdet
Expert Mod 2.5K+
P: 2,851
what is the difference between different importing options available in python

import time
from time import sleep
from time import *
When you import a module, three things take place. A new namespace is created that serves as a namespace for all the objects in the imported module. The code contained in the module is executed in that namespace. A name is created that refers to the module namespace, and the name matches the name of the module. Following is an interactive example:
Expand|Select|Wrap|Line Numbers
  1. >>> import time  # Loads and executes the module "time"
  2. >>> time.ctime()  # Accesses a member of module "time"
  3. 'Mon Mar 24 19:49:39 2008'
  4.  
To load a specific object from a module into the current namespace:
Expand|Select|Wrap|Line Numbers
  1. >>> from time import ctime
  2. >>> ctime()
  3. 'Mon Mar 24 19:49:55 2008'
  4.  
To load all the objects from module time, except for those whose name starts with an underscore, into the current namespace:
Expand|Select|Wrap|Line Numbers
  1. >>> from time import *
  2. >>> clock()
  3. 2.5142860335601313e-006
  4. >>> 
Mar 25 '08 #2

Post your reply

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