Importing is partially working...

Dwight GoldWinde Dwight at GoldWinde.com
Sun Aug 9 01:45:04 EDT 2015


I am trying to import and function.
The function (humprint) is defined in a .py module inside the same folder as
the executing code.
I am put traces in the Functions.py module to show that it works okay there
(Python 3.4).

Here is the code of the Functions.py module:

try: 
print (callable(humprint))
except NameError:
print ('humprint not defined')
def humprint (sentence):
import random
import time
import sys
for char in sentence:
sys.stdout.write (char)
sys.stdout.flush ()
part_second = random.randint(1, 100) / 400
time.sleep(part_second) # delays for x seconds
print (callable(humprint))
sentence = 'Testing humprint inside of the same module'
humprint (sentence)


And here is the code for the calling module:

name = 'Jim'
coach = 'Dwight'
import importlib
sentence = 'Hi, there, ' + name + '. My name is ' + coach + '. I will be
your coach today.'
from Functions.py import humprint
humprint (sentence)

And here are the results of running the calling module:

humprint not defined
True
Testing humprint inside of the same moduleTraceback (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 "Intro.py", line 5, in <module>
    from Functions.py import humprint

ImportError: No module named 'Functions.py'; 'Functions' is not a package




So, it seems like it is accessing the module, but not the function?


Please advise!


With appreciationŠ.


BIG SMILE...


Always, Dwight




www.3forliving.key.to (video playlist on YouTube)
www.couragebooks.key.to (all my books on Amazon)







-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20150809/3edc5bd4/attachment.html>


More information about the Python-list mailing list