需要 python 帮助

发布于 2024-08-05 11:52:20 字数 1296 浏览 3 评论 0原文

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()

嘿有人能帮我找出代码中的错误吗 它说缩进中制表符和空格的使用不一致

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

混吃等死 2024-08-12 11:52:20

我编辑了您的帖子,将所有选项卡替换为 。您需要删除这些行上的缩进并用空格将其重新排列。有些编辑器可以为您做到这一点,但我不知道您使用的是哪个编辑器。

如果您认真对待 Python,则应该重新配置编辑器,以便在按下 Tab 键时始终插入 4 个空格。您还可以尝试更改制表符提供的缩进量,或者在某些编辑器中打印制表符的可见符号,以便您可以看到问题出在哪里。

I edited your post to replace all the tabs with <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. 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.

难如初 2024-08-12 11:52:20

不幸的是,Stack Overflow 上的代码格式化程序似乎将所有内容都变成了空格。但这个错误是不言自明的。与花括号语言(如 C、C++ 和 Java)不同,Python 使用缩进来标记代码块。该错误意味着块缩进不正确。

Unfortunately, it looks like the code formatter here on Stack Overflow turns everything into spaces. 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. The error means that a block is improperly indented.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文