我是新来与谷歌Colab工作,并有问题从另一个文件导入代码。为了简化这个过程,我安装了我的驱动器并上传了所有相关的数据和函数,但是我不能访问任何用户定义的函数。有没有更好的方法
我一直在使用python的import lib
from importlib.machinery import SourceFileLoader
def loadClassifier():
PROJECT_PATH = "/content/gdrive/My Drive/Colab Notebooks"
classifier = SourceFileLoader('imdbClassifier',
'/'.join([PROJECT_PATH,'reviews.ipynb'])).load_module()
print(dir(classifier))
return
loadClassifier()
the output I get is
['__builtins__', '__doc__', '__file__', '__loader__', '__name__',
'__package__', '__spec__']
according to python documentation I was expecting
"If the object is a module object, the list contains the names of the
module’s attributes"
but I try to
print(classifier.preTrained()) I get
"AttributeError: module 'imdbClassifier' has no attribute 'preTrained'"
目前没有回答
相关问题 更多 >
编程相关推荐