vegaseat

origin of Python module

Mar 13th, 2015
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.07 KB | None | 0 0
  1. ''' module_origin2.py
  2. Where does a given module come from?
  3. use os.path.dirname(module.__file__)
  4. import the modules you want to check
  5.  
  6. can be as simple as ...
  7. import pip
  8. print(pip)
  9.  
  10. also ...
  11. import inspect
  12. help(inspect.getmodule)  # under FILE
  13. print(inspect.getmodule(inspect.getmodule))
  14.  
  15. or (under FILE)...
  16. import collections
  17. help(collections)
  18. '''
  19.  
  20. import os
  21. import pip
  22. import pygame as pg
  23. import numpy as np
  24.  
  25. def module_location(module_name):
  26.     print(module_name)
  27.     print(os.path.dirname(module_name.__file__))
  28.  
  29. # testing ...    
  30. module_location(os)
  31. module_location(pip)
  32. module_location(pg)
  33. module_location(np)
  34.  
  35.  
  36. ''' result with Python33 ...
  37. <module 'os' from 'C:\\Python33\\lib\\os.py'>
  38. C:\Python33\lib
  39. <module 'pip' from 'C:\\Python33\\lib\\site-packages\\pip\\__init__.py'>
  40. C:\Python33\lib\site-packages\pip
  41. <module 'pygame' from 'C:\\Python33\\lib\\site-packages\\pygame\\__init__.py'>
  42. C:\Python33\lib\site-packages\pygame
  43. <module 'numpy' from 'C:\\Python33\\lib\\site-packages\\numpy\\__init__.py'>
  44. C:\Python33\lib\site-packages\numpy
  45. '''
Advertisement
Add Comment
Please, Sign In to add comment