Python-ImportError:无法导入名称“ HelloW”

色拉

我有一个名为pack1的文件夹,以及两个名为Task1和HelloW的python文件。由于某种原因,我收到此错误:

ImportError: cannot import name 'HelloW'

这是代码:

# file HelloW
class HelloW:
    name = "John Doe"

    def print_hello(self):
        print("Hello, %s" % self.name)


#file Task1
from pack1 import HelloW

hw = HelloW()
hw.print_hello()
野兔

我建议将HelloW.py重命名为hellow.py(根据http://legacy.python.org/dev/peps/pep-0008/#package-and-module-names模块和程序包应使用全小写的名称)。

然后尝试更新您的import语句以HelloWhellow模块中导入

from hellow import HelloW

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Python请求ImportError:无法导入名称HeaderParsingError

Python ImportError:无法导入名称datafunc [PyML]

Python“ ImportError:无法导入名称”问题

Python,ImportError:无法导入名称AbstractLazySequence

ImportError:无法在Python中导入名称....

Python 3.5“ ImportError:无法导入名称'SomeName'

Python ImportError:无法导入名称“ __version__”

ImportError:无法导入名称is_python_keyword

python setuptools:ImportError:无法导入名称库

Python Flask蓝图-ImportError:无法导入名称应用

statsmodels ImportError中的python 3.5:无法导入名称“ _representation”

web2py python-ImportError无法导入名称

Django ImportError:无法导入名称“ python_2_unicode_compatible”

PIP(Python):ImportError:无法导入名称_remove_dead_weakref

Python /烧瓶错误:“ ImportError:无法导入名称_compare_digest”

Python PIP引发错误-ImportError:无法导入名称主要

ImportError:无法在python-social-auth中导入名称迁移

Python TwitterAPI问题... ImportError:无法导入名称ReadTimeout

ImportError:无法在python瓶中导入名称路由

python-pip:ImportError:无法导入名称主要

Python故障排除:ImportError:无法导入名称“ main”

Python3 ImportError:无法从“ http”导入名称“ cookies”

[Python] [cx-freeze] ImportError:无法导入名称“ ExcelFormulaParser”

Python cx_Freeze ImportError:无法导入名称“ idnadata”

如何解决ImportError:无法在python中导入名称splitfn

Python ImportError:无法从“包装”(变压器)导入名称“版本”

来自django.contrib.auth.views的Python导入注销注销ImportError:无法导入名称'注销'

如何在Python中从Cleverhans.compat导入标志时修复“ ImportError:无法导入名称'flags'”

我该如何解决无法ImportError:无法在python3中导入名称