470,833 Members | 1,387 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,833 developers. It's quick & easy.

print() in Python 3000 return value?

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?

Apr 2 '06 #1
10 1442
James Thiele wrote:
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
Apr 2 '06 #2
Martin chimedin:
James Thiele wrote:
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


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

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

Apr 2 '06 #3
Em Dom, 2006-04-02 ├*s 10:41 -0700, James Thiele escreveu:
Martin chimedin:
James Thiele wrote:
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


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))

--
Felipe.

Apr 2 '06 #4
Expressions like
2 + 2


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.

Apr 2 '06 #5
Felipe Almeida Lessa wrote:
Em Dom, 2006-04-02 ├*s 10:41 -0700, James Thiele escreveu:

Martin chimedin:

James Thiele wrote:
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

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))

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

Apr 2 '06 #6
bayerj wrote:
Expressions like
2 + 2


return None, too.


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

Georg
Apr 2 '06 #7
Gary Herron wrote:
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.


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
Apr 2 '06 #8
James Thiele wrote:
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)

Apr 2 '06 #9
> Sorry? 2+2 here returns 4, and certainly should with your Python.

Err. Never mind. I was thinking about assignments, like
x += 2


which returns None.

Apr 2 '06 #10
bayerj wrote:
Sorry? 2+2 here returns 4, and certainly should with your Python.


Err. Never mind. I was thinking about assignments, like
x += 2


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
Apr 3 '06 #11

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

14 posts views Thread by Marcin Ciura | last post: by
22 posts views Thread by James H. | last post: by
69 posts views Thread by Edward K Ream | last post: by
reply views Thread by Kurt B. Kaiser | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.