Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
__init_uxy.py在python中无法正常工作_Python_Python 2.7_Python 3.x - Fatal编程技术网

__init_uxy.py在python中无法正常工作

__init_uxy.py在python中无法正常工作,python,python-2.7,python-3.x,Python,Python 2.7,Python 3.x,我想在python 2.7中制作一个示例包,以明确我的概念,其结构如下所示: calculator/ main.py operations/ file1.py file2.py __init__.py new_operations/ __init__.py file3.py \uuuu init\uuuuu.py内容:(此文件位于operations文件夹中) file

我想在python 2.7中制作一个示例包,以明确我的概念,其结构如下所示:

calculator/ main.py operations/ file1.py file2.py __init__.py new_operations/ __init__.py file3.py
\uuuu init\uuuuu.py
内容:(此文件位于operations文件夹中)

file1.py
content:(此文件位于operations文件夹中)

file2.py
content:(此文件位于operations文件夹中)

\uuuu init\uuuuu.py
内容:(此文件位于“新建操作”文件夹中)

file3.py
content:(此文件位于新的\u操作文件夹中)

现在,当我运行
main.py
时,出现以下错误:

Traceback (most recent call last):
  File "C:\Python27\mycodes\calculator\main.py", line 3, in <module>
    from operations import power
ImportError: cannot import name power
回溯(最近一次呼叫最后一次):
文件“C:\Python27\mycodes\calculator\main.py”,第3行,在
从运营中进口电力
ImportError:无法导入名称权限

谁能告诉我,我犯了什么错误?帮帮我。

您的计算器模块中缺少“添加”功能。如果您创建一个“add”函数,我会假设代码可以工作

可以尝试在模块计算器中执行此操作:

def add(num1,num2):
    print(num1+num2)
    return num1+num2;
如果不希望在计算时打印,请删除打印语句


希望这有帮助

在“main.py”文件中使用以下行:


但在所有这些中,有什么会让你认为
计算器.add
会起作用呢?您认为您在哪里定义它?
计算器
不是一个包,没有
添加
<代码>操作是一个包,您可以从操作导入添加中执行
,但
计算器
不是一个包。
def add(a,b):
    return(a+b)

def sub(a,b):
    return(a-b)
def mul(a,b):
    return(a*b)

def div(a,b):
    return(a/b)
from .file3 import power
def power(a,b):
    return(a**b)
Traceback (most recent call last):
  File "C:\Python27\mycodes\calculator\main.py", line 3, in <module>
    from operations import power
ImportError: cannot import name power
def add(num1,num2):
    print(num1+num2)
    return num1+num2;
from operations.new_operations import power