[Tutor] The very first program in python

Alan Gauld alan.gauld at btinternet.com
Thu Nov 12 12:49:10 EST 2015


On 12/11/15 17:16, Sajjadul Islam wrote:
> Hello
>
> I have coded the first snippet in python  - defined a function ,

Give us a clue - show us the code.

> getting error if I try call the function from the IDLE window.

If you defined your function in a separate module using IDLE
you can use the run menu to run the module directly. That will
in turn load it into the IDLE shell for you to use.

Alternatively import the module directly in the shell.

> ///////////////////////////////////
>
> Traceback (most recent call last):
>    File "<stdin>", line 1, in <module>
> NameError: name 'print_lol' is not defined
>

> print_lol is the name of the function that is declared and defined inside
> the file called nester.py and IDLE is called in the same path. What is that
> I am missing here ?

Try running nester.py from IDLE.

Alternatively try typing

import nester
nester.print_lol()
or

from nester import print_lol
print_lol()

Its probably worth including a note of OS and Python version
in future posts.

HTH
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list