简体   繁体   中英

Importing local python files

I need some help importing a local python file into another file.

for example I have a file named calculator.py and want to import it into another file called file.py . When I run the .py file it imports (using Hydrogen for atom). However, when I call a function from the file it says it can't be found.

from calculator.py:

def addition(a,b):
    c = a + b
    return(c)

In another file:

import calculator as calc

calc.addition(2,2)

Returns:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-4-d35e30d24b34> in <module>()
----> 1 calc.addition(2,2)

AttributeError: module "calculator" has no attribute "addition"

更改了分支,它似乎可以工作。

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