The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Python Programming
|
return printed..
Discuss return printed.. in the Python Programming forum on Dev Shed. return printed.. Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

July 1st, 2003, 05:07 AM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
|
return printed..
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!
Mark.
|

July 1st, 2003, 10:00 AM
|
|
Junior Member
|
|
Join Date: Jun 2003
Posts: 6
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
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)
|

July 1st, 2003, 12:02 PM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
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.
Mark.
|

July 1st, 2003, 10:52 PM
|
|
Contributing User
|
|
Join Date: Mar 2003
Posts: 325
Time spent in forums: 7 h 58 m 36 sec
Reputation Power: 11
|
|
|
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 ??
Cheers
|

July 2nd, 2003, 02:59 AM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
|
Buffering
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
Any ideas?
Mark.
|

July 10th, 2003, 06:34 PM
|
|
Tattooed Python-Lovin' Freak-Boy
|
|
Join Date: Dec 2001
Location: orange county, CA
Posts: 16
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
you could just print the result of the function instead of printing within the function:
Code:
def doubler(x):
return 2 * x
print doubler(20)
make sense?
|

July 10th, 2003, 07:33 PM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
|
Mmmm..no?
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.
Thanks anyway,
Mark.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|