[Twisted-Python] script can be used as namespace?
![](https://secure.gravatar.com/avatar/147f37c31c5295fd8afb9c16f651d706.jpg?s=120&d=mm&r=g)
I am working on an example: from twisted.internet.app import Application from twisted.internet.protocol import Protocol, Factory class Fibonacci(Protocol): """Serve a sequence of Fibonacci numbers to all requesters""" def dataReceived(self, data): self.factory.new = self.factory.a + self.factory.b self.transport.write('%d' % self.factory.new) self.factory.a = self.factory.b self.factory.b = self.factory.new def main(): import fib_server # Use script as namespace f = Factory() f.protocol = fib_server.Fibonacci f.a, f.b = 1, 1 application = Application("Fibonacci") application.listenTCP(8888, f) application.save() if'__main__' == __name__: main() I have questions as the following: 1. Is application.save( ) that make Fibonacci.tap file? 2. testing on "twistd -f Fibonacci.tap" got message "Failed to load application: No module named fib_server".Can we use script as namesp? -- Steve Han
![](https://secure.gravatar.com/avatar/7ed9784cbb1ba1ef75454034b3a8e6a1.jpg?s=120&d=mm&r=g)
On Sun, 31 Dec 2006 10:34:49 +0800, Steve Han <hxianping@gmail.com> wrote:
Yes. However, this is not the recommended way to create TAP files, and TAP files themselves aren't even very highly recommended any more. You may want to spend your time look at mktap plugins, .tac files, or twistd plugins (which will be available in Twisted 2.5, which will be out shortly).
2. testing on "twistd -f Fibonacci.tap" got message "Failed to load application: No module named fib_server".Can we use script as namesp?
You need to fix your PYTHONPATH so that fib_server is importable. http://python.org/doc/tut/node8.html#SECTION008110000000000000000 Jean-Paul
![](https://secure.gravatar.com/avatar/7ed9784cbb1ba1ef75454034b3a8e6a1.jpg?s=120&d=mm&r=g)
On Sun, 31 Dec 2006 10:34:49 +0800, Steve Han <hxianping@gmail.com> wrote:
Yes. However, this is not the recommended way to create TAP files, and TAP files themselves aren't even very highly recommended any more. You may want to spend your time look at mktap plugins, .tac files, or twistd plugins (which will be available in Twisted 2.5, which will be out shortly).
2. testing on "twistd -f Fibonacci.tap" got message "Failed to load application: No module named fib_server".Can we use script as namesp?
You need to fix your PYTHONPATH so that fib_server is importable. http://python.org/doc/tut/node8.html#SECTION008110000000000000000 Jean-Paul
participants (3)
-
Jean-Paul Calderone
-
Steve Freitas
-
Steve Han