简体   繁体   English

如何修复AttributeError:模块'testing2'没有属性'printPackage'?

[英]How to fix AttributeError: module 'testing2' has no attribute 'printPackage'?

I have this first module: 我有第一个模块:

#testing1
import testing2
choice = input('Enter your choice:')

def calculateMenuPrice(choice):
    testing2.printPackage(menuList)
calculateMenuPrice(choice)

and the second module: 第二个模块:

#testing2
import testing1
menuList = testing1.calculateMenuPrice(choice)
def printPackage(menuList):
    for x in menuList:
        if menuList == '1':
            return('''
----------
Menu List
----------
1. Jelly Fish Yee Sang with Pear
2. Dried Seafood with Fish Soup 
3. Steamed Sea Water Grouper

''')        
        elif menuList == '2':
             return('''
----------
Menu List
----------
1. Jelly Fish Yee Sang with Pear
2. Shark Fin Soup with Crab Meat
3. Steamed River Patin Fish
''')
        elif menuList == '3':
            return('''
----------
Menu List
----------
1. Salmon Fish Yee Sang with Pear
2. Steamed Classic Abalone Soup
3. Steamed Bamboo Fish

''')

        elif menuList == '4':
            return('''
----------
Menu List
----------
1. Abalone Yee Sang with Pear
2. Mini Classic Steam Soup
3. Steamed Local Pomfret Fish

''')

the testing2 module requires me to use a for loop to loop through the menu and no hardcoded codes but i get the: testing2模块要求我使用for循环遍历菜单,没有硬编码的代码,但是我得到了:

AttributeError: module 'testing2' has no attribute 'printPackage'

Help and suggestion please. 请帮助和建议。 I'm just started learning python. 我刚刚开始学习python。 Thanks. 谢谢。

From what I can see, the reason that you are getting the error is because both modules are reliant on the other. 从我所看到的,您得到错误的原因是因为两个模块都依赖于另一个。

If you have a look at line 1 of testing1 , you see an import statement. 如果看一下testing1第1行,则会看到一个import语句。 This then runs testing2 . 然后运行testing2 The first line of this module is to import testing1 . 该模块的第一行是导入testing1 When Python runs this module, it finds a reference to testing2.printPackage , which has not been imported yet. 当Python运行此模块,它找到一个参考testing2.printPackage尚未进口的呢。

To fix this, try to sort out the dependencies of both modules, and see if you can combine both into one module. 要解决此问题,请尝试整理两个模块的依赖关系,然后查看是否可以将两个模块组合到一个模块中。

The alternative option is, before the import statement in testing2 , is to define the printPackage function as so: 另一种选择是,在testing2的import语句testing2 ,是这样定义printPackage函数:

printPackage = lambda menuList: None

and then continue your module, later on re-defining the printPackage function. 然后继续您的模块,稍后重新定义printPackage函数。

Hopefully this will then work. 希望这会起作用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何修复 AttributeError: 'module' 对象没有属性 'function'? - How to fix AttributeError: 'module' object has no attribute 'function'? 如何修复“AttributeError:‘module’对象没有属性‘x’”? - how to fix "AttributeError: 'module' object has no attribute 'x' "? 如何在wfastcgi中修复“ AttributeError:模块没有属性'wsgi'” - How to fix “AttributeError: module has no attribute 'wsgi' ” in wfastcgi 如何修复:AttributeError:模块“整洁”没有属性“配置” - How to fix: AttributeError: module 'neat' has no attribute 'config' 如何修复 AttributeError:模块“tensorflow”没有属性“ConfigProto” - How can I fix AttributeError: module 'tensorflow' has no attribute 'ConfigProto' 如何修复 AttributeError:模块“requests.sessions”没有属性“post” - How to Fix AttributeError: module 'requests.sessions' has no attribute 'post' 如何修复此错误“AttributeError:模块‘socket’没有属性‘gethostname’” - How to fix this error "AttributeError: module 'socket' has no attribute 'gethostname'" 如何修复 AttributeError:模块“magpylib”没有属性“源” - How to Fix AttributeError: module 'magpylib" has no attribute 'source' 如何修复“AttributeError:模块'keras.backend'没有属性..” - How to fix "AttributeError: module 'keras.backend' has no attribute.." AttributeError: 模块 'numpy' 没有属性 'testing' - AttributeError: module 'numpy' has no attribute 'testing'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM