Python:函数:不识别依赖项

2024-09-27 23:23:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我对用Python编写模块相当陌生。
我使用python3.5

我有个剧本叫描述工具箱.py包含我希望能够调用的函数,例如:

#describeToolbox.py
import shelve

def getRawData(prefix):
    shelfFile = shelve.open('data'+prefix)
    df = shelfFile['data'+prefix]
    shelfFile.close()
    return df

这意味着从搁置文件中检索数据帧
现在,我在控制台中编写以下语句:

In [7]:import shelve
       import describeToolbox as TB

In [8]:TB.getRawData('Myprefix')

Out [8]:
    ---------------------------------------------------------------------------
    NameError                                 Traceback (most recent call last)
    <ipython-input-9-67160af666cc> in <module>()
    ----> 1 TB.getRawData('Myprefix')

    C:\Users\Math\Documents\Docs\Commos\Notebooks\describeToolbox.py in getRawData(prefix)
          1 def getRawData(prefix):
    ----> 2     shelfFile = shelve.open('data'+prefix)
          3     df = shelfFile['data'+prefix]
          4     shelfFile.close()
          5     return df

    NameError: name 'shelve' is not defined

它给我一个错误消息,说模块'搁置',依赖关系,没有定义。你知道吗

基本上,我不知道哪里是导入所有依赖项的正确位置,以便我的函数可以在需要导入时加载它们。你知道吗

我想写一个我经常在一个模块中使用的函数库,并在需要时调用它们。你知道吗

谢谢你的帮助!你知道吗


Tags: 模块函数pyimportdfclosedataprefix

热门问题