Ok, what I want to do is return any printed data from a function, or class, similar to Zope's "return printed" statment in Python scripts. I figured it might work just returning printed from the function but that obviously causes an error (global variable not defined).
Thanks alot guyz.
Any help would be great!
I don't quite understand what you are trying to do. Could you elaborate a little more. (I think the problem is I'm not familiar with Zope)
Ok , nothing to do with Zope. Say you have a function which returns no value (prints instead) and you want to get this printed data as a return value so you can pass it to another function.
In Zope, at the end of a Python script you need to include "return printed" or no output will be sent, the "printed" name must hold all the values printed by print, but I cant work out how to do this in Python.
I could write a String buffer class and use it instead of print but I'd rather capture the values printed another way, i.e. but returning printed, but that doesnt seem to exist , maybe I'll suggest they make it possible in a latter version!
Hope this is a little clearer.
I assume they just use a buffer for that, and then you return it and it prints whatever is returned in that buffer.
How else could you do it ?
I doubt you can capture something that is printed to output ??
Yeah i kinda knew that , was just looking for another more, elegant, way. I'd quite like to send stdout to stdin, but i can't work out how to read this back out into a variable simply because I dont know the in's and out of raw_input.
Ive done it before by sending stdout to a file then reading it back in, but it seems a bit of a waist. I've also used a String Buffer but then this is what i was trying to avoid
July 10th, 2003, 07:34 PM
you could just print the result of the function instead of printing within the function:
return 2 * x
July 10th, 2003, 08:33 PM
LOL sorry, quite a comical responce dude.
Not what i really wanted to do, what i wanted to do was capture printed output or use a fuction which would store values as a string for use latter.
The problem being that you can't pass a print stament to another fuction. Yes i could just so variable += 'string' but its not very elegant. I wrote a class which worked like this but opted for another way of doing it.
I'm working on a templated content managment engine (kinda like zope but without the dynamic content, designed purly for content managment, portability and ease of use) and wanted to pass a functions output (printed) to re.sub. But I found a nicer way to do it using split.