English 中文(简体)
推断:除说明[复制]外,意外失常
原标题:IndentionError: unexpected indent, in except statement [duplicate]

我正在制作一个“灰色”节目,如果我的服务器上台的话,会对其进行检查。 如果是 t,它会tw倒。 之后,它会回头来。

但是,当我执行我的法典时,我发现这一错误:

  File "Tweet_bot.py", line 31
    textfile = open( /root/Documents/server_check.txt , w )
    ^
IndentationError: unexpected indent

我的分节守则如下:

try :
    response = urlopen( url )
except HTTPError, e:
    tweet_text = "Raspberry Pi server is DOWN!"
    textfile = open( /root/Documents/server_check.txt , w )
    textfile.write("down")
    textfile.close()

except URLError, e:
    tweet_text = "Raspberry Pi server is DOWN!"
    textfile = open( /root/Documents/server_check.txt , w )
    textfile.write("down")
    textfile.close()
else :
    html = response.read()
    if textfile = "down":
        tweet_text = "Raspberry Pi server is UP!"
        textfile = open( /root/Documents/server_check.txt , w )
        textfile.write("up")
        textfile.close()
    if textfile = "up":
        tweet_text = ""
        pass
if len(tweet_text) <= 140 and tweet_text > 0:
    api.update_status(status=tweet_text)
else:
    pass
最佳回答

你们正在混合制片和空间:

>>> from pprint import pprint
>>> pprint(   
...     tweet_text = "Raspberry Pi server is DOWN!"
...         textfile = open( /root/Documents/server_check.txt , w )
...    .splitlines())
[  ,
      tweet_text = "Raspberry Pi server is DOWN!" ,
 "	textfile = open( /root/Documents/server_check.txt , w )"]

注:在第二行开始时,但第一个有4个空间。

灰 Python将tab片扩大到第8栏,该栏比第1行的4个空间多。 因此,第二行被压缩到2<>2>>>>> 降级水平,而第一级则只降级。

甲型六氯环己烷(PEP 8)建议使用only/em>的空间:

Spaces are the preferred indentation method.

and

装有制片和空地混合物的 Python2代码应完全改用空间。

as getting your tabs configured correctly and not accidentally muck up indentation by mixing in a few spaces is hard.

请您的编辑在您的编辑时将表格转换成空间;这样,你才能使用TAB的关键板块,而不落入这一陷阱。

问题回答

暂无回答




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...