[Twisted-Python] Page.renderString returns Deferred at <addr> current result: 'blah'
William Waites
ww at groovy.net
Fri Dec 24 16:05:07 EST 2004
On Fri, Dec 24, 2004 at 12:10:16PM -0800, Alan Ezust wrote:
> I'm playing around with Twisted for my first time, and I noticed that
> page.renderString() returns a string like this:
>
> <Deferred at 0x4054616c current result: '<html>\n <head>\n
> <title>Greetings!</title>\n </head>\n <body>\n <h1
> style="font-size: large">Now I will greet you:</h1>\n Hi My name
> is\n </body>\n</html>'>
>
> First, why the Deferred result?
I suspect it is because renderString might well want to do other
operations in order to construct the string, and the result may
not be immediately available.
> Second, what if I just want the actual string? What method should I
> call? Or am I supposed to do something else to this before getting the
> renderString?
You could do somethign like:
def _cbDoSomethingWithString(str):
print str
page.renderString().addCallback(_cbDoSomethingWithString)
There is also a helper function that you can use:
s = page.renderString()
from twisted.trial.util import wait
s = wait(s)
though I am not sure how advisable it is to use that, depending on
what exactly it is you are trying to do...
Cheers,
-w
More information about the Twisted-Python
mailing list