python custom module usage instructions

高洛峰
Release: 2017-03-16 11:40:04
Original
1791 people have browsed it

保存一个hello.py文件在F:/data/python目录下

  • hello.py

>>> def hello(x):    print x
Copy after login

  • 目录

python custom module usage instructions

  • 导入

>>> import sys>>> sys.path.append('F:/data/python') #添加路径>>> import hello>>> hello.hello(5)  #调用5
Copy after login

 不改变sys.path导入自定义模块:

第一种方法:将hello2.py文件放在D:/Python27/lib/site-packages目录下

>>> import sys,pprint>>> pprint.pprint(sys.path)
['', 'D:\\Python27\\Lib\\idlelib', 'F:\\data\\s', 'D:\\Python27', 'C:\\Windows\\system32\\python27.zip', 'D:\\Python27\\DLLs', 'D:\\Python27\\lib', 'D:\\Python27\\lib\\plat-win', 'D:\\Python27\\lib\\lib-tk', 'D:\\Python27\\lib\\site-packages']>>> import hello2>>> hello2.hello()
hello,world!
Copy after login

 第二种方法:将F:/data/python路径添加到环境变量(在系统变量中,添加PYTHONPATH变量,再将路径添加到值中)

>>> import sys>>> import hello>>> hello.hello(1)1
Copy after login

 

The above is the detailed content of python custom module usage instructions. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!