IndentationError: unexpected indent

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

    #1

    IndentationError: unexpected indent

    I have this class:

    class case(blop.case) :
    def __init__(self, n, a, b):
    blop.case.__ini t__(self)
    print 'Monty Python's Flying Circus has a ' within it...'
    ...
    ...

    But I get an error when I run the .py script from shell saying:

    print 'Monty Python's Flying Circus has a ' within it...'
    ^
    IndentationErro r: unexpected indent

    I have tried to indent the print statement 8 blanks but that does not
    help. Any hints?
  • Wim Vogelaar

    #2
    Re: IndentationErro r: unexpected indent

    You have possibly unvisible tab characters in your file.
    Just copy your lines to the simple MS notepad and try again.

    Wim Vogelaar, http://home.wanadoo.nl/w.h.vogelaar/


    Comment

    • Laurent Pointal

      #3
      Re: IndentationErro r: unexpected indent

      desktop a écrit :
      I have this class:
      >
      class case(blop.case) :
      def __init__(self, n, a, b):
      blop.case.__ini t__(self)
      print 'Monty Python's Flying Circus has a ' within it...'
      ...
      ...
      >
      But I get an error when I run the .py script from shell saying:
      >
      print 'Monty Python's Flying Circus has a ' within it...'
      ^
      IndentationErro r: unexpected indent
      >
      I have tried to indent the print statement 8 blanks but that does not
      help. Any hints?
      You have also another error:
      >>print 'Monty Python's Flying Circus has a ' within it...'
      File "<stdin>", line 1
      print 'Monty Python's Flying Circus has a ' within it...'
      ^
      SyntaxError: invalid syntax

      Better:
      >>print "Monty Python's Flying Circus has a ' within it..."
      Monty Python's Flying Circus has a ' within it...



      Note: for your indentation problem, try to use an editor allowing to
      display tab and spaces and then identify the problem location, or
      replace all tabs by 4 spaces and configure the editor to only use spaces.

      Comment

      • Bjoern Schliessmann

        #4
        Re: IndentationErro r: unexpected indent

        "Wim Vogelaar" <wim.vogelaar at mc2world dot orgwrote:
        You have possibly unvisible tab characters in your file.
        Just copy your lines to the simple MS notepad and try again.
        How is he supposed to run MS notepad on X11? :)

        Regards,


        Björn

        P.S.: YES, I know there is wine.

        --
        BOFH excuse #126:

        it has Intel Inside

        Comment

        • Wim Vogelaar

          #5
          Re: IndentationErro r: unexpected indent

          Note: for your indentation problem, try to use an editor allowing to
          display tab and spaces and then identify the problem location, or replace
          all tabs by 4 spaces and configure the editor to only use spaces.
          It would be very helpful when Python would warn you when there are tabs in
          your source.

          So instead of only saying: "IndentationErr or: unexpected indent"
          there could be an additional message saying: "there are tab characters in
          that line, please remove them".

          Wim Vogelaar, http://home.wanadoo.nl/w.h.vogelaar/


          Comment

          • Wim Vogelaar

            #6
            Re: IndentationErro r: unexpected indent

            How is he supposed to run MS notepad on X11? :)
            >
            I am saying MS notepad, but any software (running on Linux) showing you
            clearly the tabs will help.

            It would also be very convenient when python would deal with tabs in a human
            friendly way.

            Wim Vogelaar, http://home.wanadoo.nl/w.h.vogelaar/


            Comment

            • Dave Borne

              #7
              Re: IndentationErro r: unexpected indent

              It would be very helpful when Python would warn you when there are tabs in
              your source.
              invoke python with the -t option for warnings about tabs or -tt for errors.

              -Dave

              Comment

              Working...