2009-09-16 96 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