print() in Python 3000 return value?

J

James Thiele

I noticed in PEP 3000 that print will become a function. The PEP
references a thread where Guido explains this decision. The thread does
not specify what the function will return. Has this been decided?
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

James said:
I noticed in PEP 3000 that print will become a function. The PEP
references a thread where Guido explains this decision. The thread does
not specify what the function will return. Has this been decided?

My intuition is that it should be a procedure (i.e. returning None).

What do you want it to return?

Regards,
Martin
 
J

James Thiele

Martin chimedin:
My intuition is that it should be a procedure (i.e. returning None).
What do you want it to return?

Regards,
Martin

The string that was printed. It could be useful inside expessions:

message = "I don't need to see all of this:%s" % print(s)
 
F

Felipe Almeida Lessa

Em Dom, 2006-04-02 às 10:41 -0700, James Thiele escreveu:
Martin chimedin:

The string that was printed. It could be useful inside expessions:

message = "I don't need to see all of this:%s" % print(s)

Or maybe:

for i in sequence:
mylist.append(print(i))
 
B

bayerj

Expressions like

return None, too. I am not certain, but as far as I know this has some
major design reasons. Thus I am certain, that print() will return None
also.
 
G

Gary Herron

Felipe said:
Em Dom, 2006-04-02 às 10:41 -0700, James Thiele escreveu:



Or maybe:

for i in sequence:
mylist.append(print(i))
No no, please NO! You *know* that someday you'll want the return value
without actually printing the text.

So let's don't overload a single function with two operations. Let
"print" print, and propose a separate function (named "format" --yuck--
or some such) that returns the same text as a string.

Gary Herron
 
G

Georg Brandl

Gary said:
No no, please NO! You *know* that someday you'll want the return value
without actually printing the text.

So let's don't overload a single function with two operations. Let
"print" print, and propose a separate function (named "format" --yuck--
or some such) that returns the same text as a string.

Yes! That's really a good idea. But "format" is a bad name. Let's call it
"as_string"!

Hm, bad too. What about "text"?

No, now I know. Let it be called "str".

Georg
 
A

Atanas Banov

James said:
I noticed in PEP 3000 that print will become a function. The PEP
references a thread where Guido explains this decision. The thread does
not specify what the function will return. Has this been decided?

reading the discussion, the arguments are about "print" as of now being
a syntactic construc, an operator without apparent reason. all that is
proposed is to tuck it as a function/procedure, i.e. use parenthesis
and be able to redefine with a simple def print(...)

if you think about it, the pythonic way is for print to return None. we
use it for the side effect (stdout output)
 
B

bayerj

Sorry? 2+2 here returns 4, and certainly should with your Python.

Err. Never mind. I was thinking about assignments, like

which returns None.
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

bayerj said:
Err. Never mind. I was thinking about assignments, like


which returns None.

Actually, assignment, in Python, is a statement, not an expression.
Statements don't return anything, not even None (they don't have
a value). If print becomes a function, the question about its return
value becomes meaningful.

Regards,
Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,291
Messages
2,571,493
Members
48,160
Latest member
KieranKisc

Latest Threads

Top