自定义包及模块的导入

来源:互联网 发布:select两张表所有数据 编辑:程序博客网 时间:2024/05/29 03:22
#设置工作目录import osworkdir='C:\Users\wugx\Desktop\python_machine_learning\personal_lib'     os.chdir(workdir)#把自定义模块的路径直接加入环境变量import sysmoduledir=workdir+'\knnpackage' sys.path.append(moduledir)#编译相关.py文件,确保代码语法正确import py_compilefilename='__init__.py'filepath=moduledir+'\\'+filenamepy_compile.compile(filepath)filename='knn.py'filepath=moduledir+'\\'+filenamepy_compile.compile(filepath)#导入自定义包,调用其中模块的函数from knnpackage import *group,labels=knn.createDataSet()inx=[0,0]knn.classify(inx,group,labels,3)#直接导入自定义模块,调用其中函数import knn group,labels=knn.createDataSet()inx=[0,0]knn.classify(inx,group,labels,3)

原创粉丝点击