[Tutor] def problem

Benoit Dupire bdupire@seatech.fau.edu
Mon, 11 Jun 2001 15:15:07 -0400


--------------E3E5CA49B2922E202ECD33F7
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit



Ron wrote:

> I'm having problems with "def". Here's what I put in and save as
> "test122" def here():
>     print "hello"
>     print
>     print "that was a space" This is what I get. >>> import test123
> >>> here()
> Traceback (most recent call last):
>   File "<pyshell#1>", line 1, in ?
>     here()
> NameError: name 'here' is not defined
> >>>

This is because the function called here() does not exist in the current
namespace.
here() lives in the module namespace (test123)
Thus, to call the function, you must prefix it with the name of the
module.
It becomes:

test123.here()


--
Benoit Dupire


--------------E3E5CA49B2922E202ECD33F7
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<body bgcolor="#FFFFFF">
&nbsp;
<p>Ron wrote:
<blockquote TYPE=CITE><style></style>
<font face="Arial"><font size=-1>I'm
having problems with "def". Here's what I put in and save as "test122"</font></font>&nbsp;<font face="Arial"><font size=-1>def
here():</font></font>
<br><font face="Arial"><font size=-1>&nbsp;&nbsp;&nbsp; print "hello"</font></font>
<br><font face="Arial"><font size=-1>&nbsp;&nbsp;&nbsp; print</font></font>
<br><font face="Arial"><font size=-1>&nbsp;&nbsp;&nbsp; print "that was
a space"</font></font>&nbsp;<font face="Arial"><font size=-1>This is what
I get.</font></font>&nbsp;<font face="Arial"><font size=-1>>>> import test123</font></font>
<br><font face="Arial"><font size=-1>>>> here()</font></font>
<br><font face="Arial"><font size=-1>Traceback (most recent call last):</font></font>
<br><font face="Arial"><font size=-1>&nbsp; File "&lt;pyshell#1>", line
1, in ?</font></font>
<br><font face="Arial"><font size=-1>&nbsp;&nbsp;&nbsp; here()</font></font>
<br><font face="Arial"><font size=-1>NameError: name 'here' is not defined</font></font>
<br><font face="Arial"><font size=-1>>>></font></font></blockquote>

<p>This is because the function called here() does not exist in the current
namespace.
<br>here() lives in the module namespace (test123)
<br>Thus, to call the function, you must prefix it with the name of the
module.
<br>It becomes:
<p>test123.here()
<br>&nbsp;
<p>--
<br>Benoit Dupire
<br>&nbsp;
</body>
</html>

--------------E3E5CA49B2922E202ECD33F7--