tags:

views:

127

answers:

2
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.

A: 

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())
Chris Bunch
ctime no longer requires an argument. Those docs are from a really old version of python (1.6). Even if it did, I think you'd get a TypeError, not a 'invalid syntax' (so presumably a SyntaxError) as being reported here.time.ctime() will return the current time since Python 2.1.
Andy
+1  A: 

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

Use:

print (time.ctime())

and it should be fine.

Andy