print()语法错误

时间:2016-08-12 04:06:30

标签: python syntax-error

我们的讲师给了我们一些代码来帮助我们完成一项任务,当我尝试运行它时,我遇到语法错误。我根本没有触及过这些代码,它意味着在没有我们改变任何东西的情况下运行。这是我们给出的代码的一半:

class Flusher(MessageProc):
        def main(self):
            super().main()
            print('before start message')
            self.receive(
                Message(
                    'start',
                    action=self.flush))
            print('after start message')
            self.receive(
                Message(
                    ANY,
                    action=lambda data:print('The first thing in the queue after the flush is', data)))
        def flush(self, *args):
            self.receive(
                Message(
                    ANY,
                    action=self.flush), # recursively call the flush method
                TimeOut(
                    0,
                    action=lambda: None)) # when no more messages return

抛出异常的行是:

action=lambda data:print('The first thing in the queue after the flush is', data)

这是我第一次使用Python,所以请有人解释什么是错的,我应该怎么做才能解决它。

编辑:错误跟踪是:

File "./demo_timeout.py", line 18
    action=lambda data:print('The first thing in the queue after the flush is' + data)))
                           ^
SyntaxError: invalid syntax

1 个答案:

答案 0 :(得分:1)

该代码是Python 3,您尝试使用Python 2运行它。如果您在Python 3中运行它,那么您应该很好。

如何切换到3完全取决于您的执行环境,但是您已经拥有一个名为python3的命令的机会很大;如果是这样,您应该使用它而不是python来运行提供的代码。

如果您还没有python3,那么您需要安装它,不过您要在系统上安装软件。

相关问题