若要获取模块的文件名为filename.py,在cmd中输入下面的代码即可获取指定模块的路径:
import os os.<a href="https://www.gaodaima.com/tag/path" title="查看更多关于path的文章" target="_blank">path</a>.abspath('.filename.py') #获得你要导入的模块的路径 'C:Users14469Desktopuntitledfilename.py'
www#gaodaima.com来源gaodai#ma#com搞*!代#%^码$网搞代码
复制刚才的路径,然后加到sys.path即可导入模块:
import sys sys.path.append('C:Users14469Desktopuntitledfilename.py' )
更多Python知识请关注云海天Python教程栏目。
来源:搞代码网:原文地址:https://www.gaodaima.com