“print expr”的语法错误无效?

发布于 2024-08-05 19:23:04 字数 1209 浏览 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)

        """while 1:

        data = fd.read(1024)

        if not len(data):

        break

        sys.stdout.write(data)"""

        fd.close();

        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)

        while 1:

            data2 = fd2.read(1024)

        if not len(data2):

            break

        sys.stdout.write(data2)

        fd2.close()

        print time.ctime()

        print " ending thread\n"

i=-1

while i<0:

current = testit()

time.sleep(0.001)

current.start()

我收到一条错误,指出该行的语法无效:

print time.ctime()

请帮助我。

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)

        """while 1:

        data = fd.read(1024)

        if not len(data):

        break

        sys.stdout.write(data)"""

        fd.close();

        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)

        while 1:

            data2 = fd2.read(1024)

        if not len(data2):

            break

        sys.stdout.write(data2)

        fd2.close()

        print time.ctime()

        print " ending thread\n"

i=-1

while i<0:

current = testit()

time.sleep(0.001)

current.start()

I'm getting an error stating invalid syntax for the line:

print time.ctime()

Please help me out.

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

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

发布评论

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

评论(2

被翻牌 2024-08-12 19:23:04

这是因为(至少在 Python 3.0 中),print 是一个函数。

使用:

print (time.ctime())

应该没问题。

This is because (in Python 3.0 onwards at least), print is a function.

Use:

print (time.ctime())

and it should be fine.

┾廆蒐ゝ 2024-08-12 19:23:04

来自此页面

ctime(...)

ctime(秒)->字符串

将纪元以来的时间(以秒为单位)转换为本地时间的字符串。

这相当于 asctime(localtime(seconds))。

ctime 需要一个参数,但您没有给它一个参数。如果您想获取当前时间,请尝试使用 time.time()。或者,如果您尝试将当前时间(以秒为单位)转换为本地时间的字符串,您应该尝试以下操作:

time.ctime(time.time())

From this page:

ctime(...)

ctime(seconds) -> string

Convert a time in seconds since the Epoch to a string in local time.

This is equivalent to asctime(localtime(seconds)).

ctime requires an argument and you aren't giving it one. If you're trying to get the current time, try time.time() instead. Or, if you're trying to convert the current time in seconds to a string in local time, you should try this:

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