python引入自定义模块的方法一种
有一个文件在D:\Python\a.txt
编写的代码在D:\Python\filefelix.py
filefelix.py的内容:
import sys def myfile(filename): '''''Print a file to the standard output.''' f = file(filename) while True: line = f.readline() if len(line) == 0: break print line, # notice comma f.close()
调用方法:
1,加载路径
sys.path.append('D:\Python')
2,加载模块
import filefelix
3,运行函数
filefelix.myfile(r'D:\Python\a.txt')
posted on 2014-05-04 23:25 Felixlovechina 阅读(208) 评论(0) 编辑 收藏 举报