Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/328.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
我正在尝试将一个模块导入到我的main.py python文件中,这两个文件都在同一个目录中_Python_Function_Import_Module_Call - Fatal编程技术网

我正在尝试将一个模块导入到我的main.py python文件中,这两个文件都在同一个目录中

我正在尝试将一个模块导入到我的main.py python文件中,这两个文件都在同一个目录中,python,function,import,module,call,Python,Function,Import,Module,Call,这是一个功能,我想导入到另一个文件(main.py)以如下方式工作: def volumeofcube(): a = int(input('Enter the length of the side:')) volume = a**3 #Rounded to one decimal place volume = str(round(volume, 1)) #The volume is added to its corresponding list v

这是一个功能,我想导入到另一个文件(main.py)以如下方式工作:

def volumeofcube():
    a = int(input('Enter the length of the side:'))
    volume = a**3
    #Rounded to one decimal place
    volume = str(round(volume, 1))
    #The volume is added to its corresponding list
    volumeofcubelist.append(volume)
    print('The volume of the cube with the side', a,'is', volume)
    return volume
但是,当我尝试导入时:

elif shape == 'cube':
    volumeofcube()

如果您尝试作为导入,则所有这些都无法找到volumes.py模块并将其导入

import volumes
or
from volumes import volumeofcube()
volumeofcube
方法的调用应为

import volumes
如果您尝试导入为

volumes.volumeofcube()
您需要去掉括号,正确的语法是:

from volumes import volumeofcube()

from volumes import volumeofcube
是您尝试执行的正确语法。如果您的.py名为
volumes
,则第二种情况下正确的语法应该是
from volumes import volumeofcube
而不使用
)(即末尾没有括号)。
from volumes import volumeofcube