简体   繁体   English

需要python帮助

[英]python help needed

import os
import sys, urllib2, urllib
import re
import time
from threading import Thread

class testit(Thread):
   def __init__ (self):
      Thread.__init__(self)
   def run(self):
        url = 'http://games.espnstar.asia/the-greatest-odi/post_brackets.php'
        data = urllib.urlencode([('id',"btn_13_9_13"),  ('matchNo',"13")])
        req = urllib2.Request(url)
        fd = urllib2.urlopen(req, data)
<TAB>fd.close()
<TAB>"""while 1:
                data = fd.read(1024)
                if not len(data):
                        break
                sys.stdout.write(data)"""
        url2 = 'http://games.espnstar.asia/the-greatest-odi/post_perc.php'
        data2 = urllib.urlencode([('id',"btn_13_9_13"),  ('matchNo',"13")])
        req2 = urllib2.Request(url2)
        fd2 = urllib2.urlopen(req2, data2)
<TAB>#prints current votes
        while 1:
                data2 = fd2.read(1024)
                if not len(data2):
                        break
                sys.stdout.write(data2)
<TAB>fd2.close()
        print time.ctime()
        print " ending thread\n"

i=-1
while i<0:
   current = testit()
   time.sleep(0.001) #decrease this like 0.0001 for more loops
   current.start()

Hey can anybody help me finding out the error in the code Its saying inconsistent use of tabs an spaces in indentation 嘿,有人可以帮我找出代码中的错误吗?俗话说,使用制表符前后不一致,在缩进中使用空格

I edited your post to replace all the tabs with <TAB> . 我编辑了您的帖子,将所有选项卡替换为<TAB> You need to delete the indentation on those lines and line it back up with spaces. 您需要删除这些行上的缩进,并在其后面加空格。 Some editors can do that for you, but I don't know which editor you are using. 一些编辑器可以为您完成此操作,但我不知道您使用的是哪个编辑器。

If you get serious about Python, you should reconfigure your editor to always insert 4 spaces when the tab key is pressed. 如果您认真对待Python,则应重新配置编辑器,以便在按Tab键时始终插入4个空格。 You can also try changing the amount of indentation provided by the tab character or in some editors print a visible symbol for the tab character so you can see where the problem is. 您也可以尝试更改制表符提供的缩进量,或者在某些编辑器中为制表符打印一个可见的符号,以便查看问题出在哪里。

Unfortunately, it looks like the code formatter here on Stack Overflow turns everything into spaces. 不幸的是,它看起来像Stack Overflow上的代码格式化程序将所有内容都变成了空格。 But the error is quite self-explanatory. 但是错误是不言自明的。 Python, unlike the curly-brace languages (like C, C++, and Java) uses indentation to mark blocks of code. Python与大括号语言(例如C,C ++和Java)不同,Python使用缩进标记代码块。 The error means that a block is improperly indented. 该错误表示块缩进不正确。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM