I'm new to python programming and I have a problem. I've been looking for the solution to it problem all day and nothing I've found so far has helped me. I'm writing a time delay program in Python, but once it hits the input for the delay it gives me an error. I've tried running it in the same program and it works, but I want the two programs to be separate.
This is the delay function in delay.py
def delayA(ina):
ina=float(ina)
print("okay!")
time.sleep(ina)
print("done!")
This is the call for it in my main
import delay.py
ina = input("Enter delay in seconds: ")
delayA(ina)
And this is the error message that I've been getting all day
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
Thank you in advance for any help!
You were almost there bar a few minor mistakes:
delay.py:
from time import sleep
def delayA(ina):
ina = float(ina)
print("okay!")
sleep(ina)
print("done!")
main.py:
#!/usr/bin/env python
from delay import delayA
ina = input("Enter delay in seconds: ")
delayA(ina)
Your only three mistakes I found were:
delayA function.from delay import delayA -- Not: import delay.pydelayA function. i.e: from foo import barIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With