【问题标题】:Getting error when trying to add python file in our current file尝试在当前文件中添加 python 文件时出错
【发布时间】:2019-11-10 23:46:48
【问题描述】:

enter image description here我在pycharm中创建了一个文件夹,并在里面创建了一个文件。想在我当前的文件中导入它。 enter image description here

【问题讨论】:

    标签: python pycharm


    【解决方案1】:

    异常是告诉你 add 没有定义,因为它不是 Python 的关键字,也不是你要导入的函数(如 from this_module import add)。

    如果你想对两个元素求和,你需要内置函数sum(它需要一个可迭代的,就像一个列表),所以你的代码会变成

    a=2
    b=3
    c=sum([a,b])
    print(c)  # 5
    

    编辑:在第二个屏幕截图之后,您需要调用 from airthmetic.airthmetic import add

    顺便说一句,这是算术

    【讨论】:

    • “从 airthmetic.airthmetic 导入添加”它的工作。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-06
    • 2016-05-29
    • 1970-01-01
    • 2022-01-23
    • 1970-01-01
    • 2015-02-16
    • 1970-01-01
    相关资源
    最近更新 更多