indendation error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • km

    indendation error

    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,ot her):
    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
    ^
    IndentationErro r: 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


  • Jarek Zgoda

    #2
    Re: indendation error

    km <km@mrna.tn.nic .in> pisze:
    [color=blue]
    > File "script.py" , line 6 self.x = x ^ IndentationErro r: 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.[/color]

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

    --
    Jarek Zgoda
    Unregistered Linux User # -1
    http://www.zgoda.biz/ JID:zgoda@chrom e.pl http://zgoda.jogger.pl/

    Comment

    • Matthew Scott

      #3
      Re: indendation error

      km wrote:
      [color=blue]
      > kindly enlighten hwo to fix this --
      > it will be great if someone can direct me to an online link regarding  the
      > rules of indendation.[/color]

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

      This document gives coding conventions for the Python code comprising the standard library in the main Python distribution. Please see the companion informational PEP describing style guidelines for the C code in the C implementation of Python.


      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.

      --
      Matthew Scott <netnews@golden spud.com>

      Comment

      Working...