[Tutor] new function and a 3 line program not working

Alan Gauld alan.gauld at freenet.co.uk
Mon Nov 29 19:01:00 CET 2004

> go to IDLE gui and define the new function
> def newLine():
>     print
> then i open another IDLE window and write the 3 line program like in
the tutorial

This is the second time this has come up recently. Which tutorial are
you using?
Does it tell you to go to a separate window to type the bit below?

> print "First Line."
> newLine()
> print "Second Line."

If so that is the problem. You cannot call newLine() in a separate
file from the one where you defined it - python doesn't know about it.
You need to *import* the file where you defined the function, like

from newline.py import newline

Ah, but reading further in your post and looking at the tutorial text
you posted, the author does NOT say create a new file. Rather
he (she?) says (or implies) to just keep on typing the program
after the function definition in the same file. That way Python
can read the file including the newline() definition.


Alan G.


The first couple of functions we are going to write have no
parameters, so the syntax looks like this:

def newLine():

This function is named newLine. The empty parentheses indicate that it
has no parameters. It contains only a single statement, which outputs
a newline character. (That's what happens when you use a printcommand
without any arguments.)

The syntax for calling the new function is the same as the syntax for
built-in functions:

print "First Line."
print "Second Line."

<AG - See, no mention of creating a new file after the function

More information about the Tutor mailing list