[英]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
this is a funtion that i want to import into another file (main.py) to work like this: 这是一个功能,我想导入到另一个文件(main.py)中以使其工作:
elif shape == 'cube':
volumeofcube()
however when I try to import: 但是,当我尝试导入时:
import volumes
or
from volumes import volumeofcube()
none of these are able to find the volumes.py module and import it 这些都无法找到volumes.py模块并将其导入
If you are trying to import as 如果您尝试导入为
import volumes
the call for volumeofcube
method should be 对
volumeofcube
方法的调用应为
volumes.volumeofcube()
if you try to import as 如果您尝试导入为
from volumes import volumeofcube()
you need to take the parenthesis off, the right syntax is: 您需要取消括号,正确的语法是:
from volumes import volumeofcube
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.