Unable to import name 'pb'

I am using Twisted 16.1.1 and python 3.4. The twisted documentation for version 16.1.1 has a tutorial that says `from twisted.spread import pb '. But when I try to import it, it gives an exception. What am I doing wrong?

Traceback (most recent call last):
File "main.py", line 10, in <module>
from twisted.spread import pb
ImportError: cannot import name 'pb'

I am watching this tutorial . This is my code:

from twisted.internet import reactor
from twisted.spread import pb

class Echoer(pb.Root):
    def remote_echo(self, st):
        print('echoing:', st)
        return st

if __name__ == '__main__':
    reactor.listenTCP(8789, pb.PBServerFactory(Echoer()))
    reactor.run()

In /usr/lib64/python3.4/site-packages/twisted/spreadthere is one folder with a name ui. There is no folder / file named pb.

I copied the file pb.pyto the python folder, now when I try to import pb, I get an exception:

Traceback (most recent call last):
File "main.py", line 2, in <module>
from twisted.spread import pb
File "/usr/lib64/python3.4/site-packages/Twisted-16.1.1-py3.4.egg/twisted/spread/pb.py", line 890
except Error, e:
            ^
SyntaxError: invalid syntax

What's happening?

+4
source share
1 answer

SyntaxError , except Error, e: Python 2. Python 3 except Error as e:.

. Python 3.

+1

All Articles