[Tutor] importing my module imports only one function

Ian D duxbuz at hotmail.com
Thu Jan 30 16:43:49 CET 2014


if I create a module called "modtest.py" like this:
 
import turtle
 
def square():
    for i in range(4):
        turtle.fd(100)
        turtle.lt(90)
 
def tri():
    for i in range(3):
        turtle.fd(100)
        turtle.lt(120)
 
 
if __name__ == "__main__":
    
    tri()
 
And then call it like this:
 
import sys
sys.path.append("D:\python\modules")
import  modtest
 
modtest.square()
modtest.tri()
 
why would I just get ability to call the 'square()' function and not the 'tri()' function.
 
I get a square and a trace back:
 
line 7, in <module>
    modtest.tri()
AttributeError: 'module' object has no attribute 'tri'
 
 
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140130/1601318c/attachment.html>


More information about the Tutor mailing list