![](/img/trans.png)
[英]Importing main.py into another module (contained in the same directory)
[英]Im trying to import a module into my main.py python file both of which are in the same directory
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
这是一个功能,我想导入到另一个文件(main.py)中以使其工作:
elif shape == 'cube':
volumeofcube()
但是,当我尝试导入时:
import volumes
or
from volumes import volumeofcube()
这些都无法找到volumes.py模块并将其导入
如果您尝试导入为
import volumes
对volumeofcube
方法的调用应为
volumes.volumeofcube()
如果您尝试导入为
from volumes import volumeofcube()
您需要取消括号,正确的语法是:
from volumes import volumeofcube
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.