我不熟悉Google 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'"