3

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!

1
  • import delay not import delay.py -- And really what you want is: from delay import delayA -- NB: Python is an indended language as per my edit. Commented Jun 25, 2014 at 4:04

1 Answer 1

3

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:

  • Lack of indentation in your delayA function.
  • from delay import delayA -- Not: import delay.py
  • Actually importing the delayA function. i.e: from foo import bar
Sign up to request clarification or add additional context in comments.

2 Comments

Not that its really important, but the lack of indentation was an error putting the code into the question box, not an error in the code itself. Thank you very much for your help though
For Googlers, "import delay.py" is the actual cause of the error message -- don't add ".py".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.