简体   繁体   中英

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:

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

If you are trying to import as

import volumes

the call for volumeofcube method should be

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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