관리 메뉴

Hee'World

module 불러오기 본문

Programming/Python

module 불러오기

Jonghee Jeon 2015. 8. 8. 17:57

임의로 만들어진 임의의 디렉토리에 저장된 Python module을 불러오는 방법


1. sys모듈에 path추가 하여 불러오기

>> import sys


>> sys.path

['',

 'C:\\Python34\\Scripts\\ipython.exe',

 'C:\\Windows\\system32\\python34.zip',

 'C:\\Python34\\DLLs',

 'C:\\Python34\\lib',

 'C:\\Python34',

 'C:\\Python34\\lib\\site-packages',

 'C:\\Python34\\lib\\site-packages\\IPython\\extensions',

 'C:\\Users\\JeonJongHee\\.ipython']


>> sys.path.append("C:/Python/myPythonmodules") >> sys.path

['',

 'C:\\Python34\\Scripts\\ipython.exe',

 'C:\\Windows\\system32\\python34.zip',

 'C:\\Python34\\DLLs',

 'C:\\Python34\\lib',

 'C:\\Python34',

 'C:\\Python34\\lib\\site-packages',

 'C:\\Python34\\lib\\site-packages\\IPython\\extensions',

 'C:\\Users\\JeonJongHee\\.ipython',

 'C:\\Python\\myPythonmodules']


>> import Mymodules

>> Mymodules.test()


2. PYTHONPATH 환경변수 설정

C:\Users\home>set PYTHONPATH=C:\Python\Mymodules C:\Users\home>c:\Python34\python.exe Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:44:40) … Type "help", "copyright", "credits" or "license" for more information. >>> import mod2 >>> print(mod2.sum(3,4)) 7





 - 참고 : https://wikidocs.net/29




Comments