代码之家  ›  专栏  ›  技术社区  ›  user161004

“打印表达式”的语法错误无效?

  •  -1
  • user161004  · 技术社区  · 16 年前
    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()
    

    2 回复  |  直到 14 年前
        1
  •  4
  •   Andy    16 年前

    这是因为(至少在Python3.0以后的版本中),print是一个函数。

    使用:

    print (time.ctime())
    

    应该没问题。

        2
  •  -2
  •   Chris Bunch    16 年前

    从…起 this page :

    ctime(…)

    将自历元起的时间(秒)转换为本地时间的字符串。

    这相当于asctime(本地时间(秒))。

    ctime time.time() 相反或者,如果试图将当前时间(以秒为单位)转换为本地时间的字符串,则应尝试以下操作:

    time.ctime(time.time())
    
    推荐文章