Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #46306
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'configure': 0.05; 'output': 0.05; 'error:': 0.07; 'see:': 0.07; '"if': 0.09; '*is*': 0.09; 'exec': 0.09; 'here?': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'skip:o 50': 0.09; 'spaces': 0.09; 'width': 0.09; 'python': 0.11; 'contents:': 0.16; 'indent': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'tab': 0.16; 'tabs': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'input': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'refers': 0.24; 'script': 0.25; 'skip:" 20': 0.27; 'header:X-Complaints-To:1': 0.27; 'correct': 0.29; "i'm": 0.30; 'code': 0.31; 'getting': 0.31; '"",': 0.31; 'file': 0.32; '(most': 0.33; 'actual': 0.34; 'problem': 0.35; 'editor': 0.35; 'expected': 0.38; 'configured': 0.38; 'to:addr:python-list': 0.38; 'recent': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'subject:there': 0.68; 'eight': 0.74; 'simulation': 0.91 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Peter Otten <__peter__@web.de> |
| Subject | Re: IndentationError: expected an indented block but it's there |
| Date | Tue, 28 May 2013 18:19:47 +0200 |
| Organization | None |
| References | <V54pt.161708$Zp1.55817@en-nntp-15.dc1.easynews.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="ISO-8859-1" |
| Content-Transfer-Encoding | 7Bit |
| X-Gmane-NNTP-Posting-Host | p5084866c.dip0.t-ipconnect.de |
| User-Agent | KNode/4.7.3 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2302.1369757998.3114.python-list@python.org> (permalink) |
| Lines | 57 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1369757998 news.xs4all.nl 15980 [2001:888:2000:d::a6]:50701 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:46306 |
Show key headers only | View raw
JackM wrote:
> Having a problem getting a py script to execute. Got this error:
>
> File "/scripts/blockIPv4.py", line 19
> ip = line.split(';')[0]
> ^
> IndentationError: expected an indented block
>
>
> I'm perplexed because the code that the error refers to *is* indented:
>
>
>
> with open('/var/www/html/mydomain.com/banlist.txt','r') as inFile:
> for line in inFile.readlines():
> ip = line.split(';')[0]
> output = os.popen( '/etc/sysconfig/iptables -A INPUT -s ' + ip
> + ' -j REJECT' )
> logFile.write(ip+' - Has been blocked\n')
>
>
> What am I missing here?
If you are mixing tabs and spaces to indent your code and have your editor
configured with a tab width other than eight your code may look correct when
it isn't. A simulation in the interactive interpreter:
The actual file contents:
>>> s = "if 1:\n\tif 2:\n \tprint 'hi'"
What you see:
>>> print s.expandtabs(4)
if 1:
if 2:
print 'hi'
>>> exec s.expandtabs(4)
hi
What Python "sees":
>>> print s.expandtabs(8)
if 1:
if 2:
print 'hi'
>>> exec s
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 3
print 'hi'
^
IndentationError: expected an indented block
Solution: configure your editor to use four spaces for indentation.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
IndentationError: expected an indented block but it's there JackM <notreal@earthlink.net> - 2013-05-28 11:32 -0400 Re: IndentationError: expected an indented block but it's there Michael Torrie <torriem@gmail.com> - 2013-05-28 09:55 -0600 Re: IndentationError: expected an indented block but it's there Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-05-28 16:01 +0000 Re: IndentationError: expected an indented block but it's there Peter Otten <__peter__@web.de> - 2013-05-28 18:19 +0200 Re: IndentationError: expected an indented block but it's there Chris Angelico <rosuav@gmail.com> - 2013-05-29 02:31 +1000 Re: IndentationError: expected an indented block but it's there Peter Otten <__peter__@web.de> - 2013-05-28 18:53 +0200 Re: IndentationError: expected an indented block but it's there Chris Angelico <rosuav@gmail.com> - 2013-05-29 17:59 +1000
csiph-web