繁体   English   中英

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

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM