indendation error

K

km

Hi all,

i create a class as below :

#!/usr/bin/python -W

class Point:

def __init__(self, x = 0, y = 0):
self.x = x
self.y = y

def __str__(self):
print '(' + str(self.x) + str(self.y) + ')'

def __add__(self,other):
return Point(self.x + other.x, self.y + other.y)


but it emits an indendation error -- i tried to fix it but in vain --
and the error message was :

File "script.py", line 6
self.x = x
^
IndentationError: expected an indented block

kindly enlighten hwo to fix this --
it will be great if someone can direct me to an online link regarding the rules of indendation.

thanks,
KM
 
J

Jarek Zgoda

km said:
File "script.py", line 6 self.x = x ^ IndentationError: expected an
indented block

kindly enlighten hwo to fix this -- it will be great if someone can
direct me to an online link regarding the rules of indendation.

Don't mix tabs and spaces in your code, use either tabs OR spaces.
 
M

Matthew Scott

km said:
kindly enlighten hwo to fix this --
it will be great if someone can direct me to an online link regarding  the
rules of indendation.

PEP 8 is the "Style Guide for Python Code" and is available here:

http://www.python.org/peps/pep-0008.html

Indentation and other code layout issues are addressed in the third section.
From personal experience, 99% of the Python code I've seen uses 4 spaces
per indent, and no TAB characters.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,173
Messages
2,570,937
Members
47,481
Latest member
ElviraDoug

Latest Threads

Top