1

I have one program on the /Desktop called hello.py

 def pri():
 print "hello"

Then I have another program on the /Desktop called run.py

from hello.py import pri 
pri()

It gives me error that no module exist.

How can I successfully import methods from other python programs in the same directory.

asked Apr 12, 2014 at 12:12

2 Answers 2

1

You simply call it hello not hello.py:

from hello import pri 
pri()

If you have a file called some_name.py, the module name is only some_name and not some_name.py.

To import all methods, do it as:

from hello import *
anon582847382
20.5k5 gold badges58 silver badges60 bronze badges
answered Apr 12, 2014 at 12:12
Sign up to request clarification or add additional context in comments.

2 Comments

lol, I think I answered his question in like 2 seconds! It's nuts how fast people can answer on this site.
thanks. and how can i import all the methods of the hello.py (assuming it has more than one method)
0

Remove the .py:

from hello import pri
 ^

You don't need the file extension when importing modules, so when you try to include it it will throw an error.

answered Apr 12, 2014 at 12:12

3 Comments

thanks. and how can i import all the methods of the hello.py (assuming it has more than one method)
@user3526694 That would be just from hello import *
@user3526694 Also if I have resolved your issue, please accept my answer. In about 4 minutes time.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.