用python从另一个程序调用程序

2024-10-17 06:31:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我是python编程新手,有个问题。我整天都在寻找解决it问题的方法,但到目前为止,我所发现的一切对我都没有帮助。我正在用Python编写一个时间延迟程序,但是一旦它碰到延迟的输入,就会给我一个错误。我试过在同一个程序中运行它,但我希望这两个程序是分开的。在

这是中的延迟函数延迟.py在

def delayA(ina):
    ina=float(ina)
    print("okay!")
    time.sleep(ina)
    print("done!")

这是我的主旋律

^{pr2}$

这是我一整天都收到的错误信息

Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 2218, in _find_and_load_unlocked
AttributeError: 'module' object has no attribute '__path__'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:/Python/inputcall.py", line 1, in <module>
    import delay.py
ImportError: No module named 'delay.py'; 'delay' is not a package

提前感谢您的帮助!在


Tags: inpy程序mostlineexceptioncallfile
1条回答
网友
1楼 · 发布于 2024-10-17 06:31:27

你几乎就在那里,除了一些小错误:

延迟.py:

from time import sleep


def delayA(ina):
    ina = float(ina)
    print("okay!")
    sleep(ina)
    print("done!")

主.py:

^{pr2}$

我发现你仅有的三个错误是:

  • 您的delayA函数缺少缩进。在
  • from delay import delayA不是:import delay.py
  • 实际导入delayA函数。i、 e:from foo import bar

相关问题 更多 >