我不知道如何修复


import time
from threading import *
class MyThread(Thread):
def __init__(self):
Thread.__init__(self)
def run(self):
for el in range(10):
print self.getName(), el
time.sleep(0.01)
thread1 = MyThread()
thread2 = MyThread()
Thread3 = MyThread()
Thread4 - MyThread()

----------------------------------------
File "C:UsersHappyPycharmProjectscrawlingtest.py", line 9
print self.getName(), el
^
SyntaxError: invalid syntax
Process finished with exit code 1

在Python 3中,print是一个函数,所以你必须像这样使用括号:

import time
from threading import *
class MyThread(Thread):
def __init__(self):
Thread.__init__(self)
def run(self):
for el in range(10):
print(self.getName(), el) # watch the change on this line
time.sleep(0.01)
thread1 = MyThread()
thread2 = MyThread()
Thread3 = MyThread()
Thread4 = MyThread()

相关内容

  • 没有找到相关文章

最新更新