[Tutor] Major Newbie Here

jfouhy at paradise.net.nz jfouhy at paradise.net.nz
Wed Apr 6 00:47:17 CEST 2005


Quoting Danny Yoo <dyoo at hkn.eecs.berkeley.edu>:

> Try:
> 
> ######
> class Spam:
>  """A meat for combining with other foods
>  It can be used with other foods to make interesting meals.
>  It comes with lots of nutrients and can be cooked using many
>  different techniques"""
> 
>  def__init__(self):
>  ## ... rest of code follows
> ######
> 
> 
> Tell us if this works out better for you.

Actually, that still won't work.

Firstly, because, as others have pointed out, there is a missing space between
the 'f' and the '_'.

But even then, if you do that at the interpreter, it won't work.

>>> class Spam:
...  """A meat for combining with other foods
...  It can be used with other foods to make interesting meals.
...  It comes with lots of nutrients and can be cooked using many
...  different techniques"""
...
>>>  def __init__(self):
  File "<stdin>", line 1
    def __init__(self):
    ^
SyntaxError: invalid syntax
>>>

The problem is that the interpreter will treat a blank line as the end of an
indented block.  If you want to define classes, functions, etc. in the
interactive interpreter, you have to do so without leaving any blank lines.

...which is another good reason to write things in scripts instead :-)

-- 
John.


More information about the Tutor mailing list