2009-09-16 115 views
-1
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 expr”的语法错误无效?

print time.ctime() 

请帮助我。

+4

您应该发布与您的问题一致的错误,正如终端中所示。 – GmonC 2009-09-16 18:55:54

+3

此外,它似乎至少已经失去了一些缩进。确保代码是正确的。 – 2009-09-16 18:58:11

回答

4

这是因为(在Python 3.0起至少),打印是一个函数。

用途:

print (time.ctime()) 

,它应该是罚款。

-2

this page

的ctime(...)

的ctime(秒) - >字符串

转换成秒的时间,因为时代在当地时间的字符串。

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

ctime需要一个参数,你没有给它一个。如果您尝试获取当前时间,请尝试使用time.time()。或者,如果你想为当前时间转换成秒,在当地时间的字符串,你应该试试这个:

time.ctime(time.time()) 
+3

ctime不再需要参数。这些文档来自Python的一个真正旧版本(1.6)。即使它有,我想你会得到一个TypeError,而不是一个'无效的语法'(因此可能是一个SyntaxError),因为这里报告。 time.ctime()将返回自Python 2.1以来的当前时间。 – Andy 2009-09-16 19:22:49