472,119 Members | 1,623 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,119 software developers and data experts.

IndentationError: unexpected indent

I have this class:

class case(blop.case):
def __init__(self, n, a, b):
blop.case.__init__(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...'
^
IndentationError: unexpected indent

I have tried to indent the print statement 8 blanks but that does not
help. Any hints?
Jun 14 '07 #1
6 34114
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/
Jun 14 '07 #2
desktop a écrit :
I have this class:

class case(blop.case):
def __init__(self, n, a, b):
blop.case.__init__(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...'
^
IndentationError: 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.
Jun 14 '07 #3
"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

Jun 15 '07 #4
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: "IndentationError: 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/
Jun 16 '07 #5
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/
Jun 16 '07 #6
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
Jun 17 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Mr. Magoo | last post: by
1 post views Thread by Rolf Kemper | last post: by
1 post views Thread by will | last post: by
1 post views Thread by Vincent | last post: by
1 post views Thread by Christopher P. Winter | last post: by
7 posts views Thread by kagard | last post: by
2 posts views Thread by Chris Seidel | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.