Posted By

magicrebirth on 12/22/09


Tagged

python module


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

gartenstuhl


Python: using Modules


 / Published in: Python
 

  1. ## Modules can be imported directly using the package or module name. Items in submodules must be accessed explicitly including the full package name.
  2.  
  3. >>> import os
  4. >>> os.path.abspath(".")
  5. 'C:\\books\\python'
  6.  
  7.  
  8. ## Modules can be imported directly using the module name, but the namespace should be named something different. Items in submodules must be accessed explicitly including the full package name:
  9.  
  10. >>> import os as computer
  11. >>> computer.path.abspath(".")
  12. 'C:\\books\\python'
  13.  
  14.  
  15. ## Modules can be imported using the module name within the package name. Items in submodules must be accessed explicitly including the full package name:
  16.  
  17. >>> import os.path
  18. >>> os.path.abspath(".")
  19. 'C:\\books\\python'
  20.  
  21.  
  22. ## Modules can be imported by importing the modules specifically from the package. Items in submodules can be accessed implicitly without the package name:
  23.  
  24. >>> from os import path
  25. >>> path.abspath(".")
  26. 'C:\\books\\python'
  27.  
  28.  
  29. ## Note:
  30. reload(module)
  31.  
  32. ## This function that reloads a module. This can be extremely useful during development if you need to update a module and reload it without terminating your program. However, objects created before the module is reloaded are not updated, so you must be careful in handling those objects.

Report this snippet  

You need to login to post a comment.