newbie question
Julia Osip
gamasutra1000 at yahoo.com
Thu Jan 1 20:31:49 EST 2004
Didnt realise I was posting into an existing topic. Whitespace was
the problem, its working now. Will consider the mailing list in the
future. Thanks very much for your help!
Sean 'Shaleh' Perry <shaleh at speakeasy.net> wrote in message news:<mailman.8.1072918504.12720.python-list at python.org>...
> On Wednesday 31 December 2003 16:14, Julia Osip wrote:
> > Hi, just started fiddling around with python, having some difficulty
> > getting the following small play program to execute. Furious
> > searching in the docs, manual, newsgroup did not avail me, does anyone
> > have any ideas what might be the problem? Some sort of whitespace
> > issue (im still unsure of whitespace rules)? I'm running Mac OS
> > 10.2.8, with MacPython 2.3.
> >
>
> you might consider joining the tutor at python.org mailing list. It is meant to
> help people new to python.
>
> > Thanks for any help you can give...
> >
> > the code
> > ...snip...
> >
> > the error
> > ...snip...
> > File "<string>", line 7
> > def __init__(self):
> > ^
> > SyntaxError: invalid syntax
> > ...snip...
>
> As you guessed it is a whitespace problem. So, let's clear up the whitespace
> rules for you.
>
> There is one key rule -- be consistent. Python does not really care if you
> use 4 space indents or 8. It does care if you try to use both. Same goes
> for mixing spaces and tabs. As Python reads your code it figures out what
> your indent style is and then enforces that for the rest of the block.
>
> When Python read your class definition the first indentation it found was for
> the docstring which was 4 spaces. Then it went to the next line of code and
> found an indentation of 8. This is what caused the error. Now, maybe this
> is because you hand indented the docstring by four spaces and then used a tab
> on the line starting with 'def'. Or maybe you thought you needed to indent
> again (you don't).
More information about the Python-list
mailing list