[Tutor] I think I'm getting ahead of myself
Thu, 20 Jul 2000 17:00:32 -0700 (PDT)
On Thu, 20 Jul 2000, Steven Gilmore wrote:
> >>> import sys
Be careful of those backslashes --- they signal a 'control' or 'escape'
character in Python and other computer languages. As a quick answer, try:
instead. (The 'r' in front of the quotes means 'raw' --- it tells Python
to treat backslashes as literal backslashes.) Of course, this is
completely unrelated to the immediate problem, which is modules and
> >>> import test
> >>> countdown(3)
> Traceback (innermost last):
> File "<pyshell#4>", line 1, in ?
> NameError: countdown
> what's the deal?
Ok, the real problem is that you need to specify the module, as well as
the name of the function. Since the countdown function is located in your
'test' module, you need to execute it as:
This is because importing a module doesn't make its functions directly
available --- you still have to give the name of the module in front.
If this is awkward, there is a way to get around this by using the
from test import countdown # just get countdown
from test import * # grab every function out of test
If you do this, then you can just say
and it should work.