472,779 Members | 1,925 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,779 software developers and data experts.

Py 3.0 print

There is/was a long discussion about the replacement for print in
Python 3.0 (I don't know if this discussion is finished):
http://mail.python.org/pipermail/pyt...er/055968.html

There is also a wiki page that collects the ideas:
http://wiki.python.org/moin/PrintAsFunction

There is the will to keep the printing operation very simple for the
most common situation, but at the same time to make it flexible
(optional no space between printed items, newline, redirection to file,
etc), such requirements can collide. Another problem is to avoid
backward compatibility problems in the source code. I post my idea here
because I think I'm not fit for the python-dev mailing list yet. I hope
posting this here is okay.

A printing operation as a function requires the (), but I think there
can be little advantages (but not many advantages, the print statement
is acceptable for me still), so I agree to make it a function.

Name: I think print() and printnl() can be fine names for the two
functions, but this can give problems, so other names can be:
write/writenl, show/shownl, echo/echonl, put/putnl, emit/emitnl,
say/saynl
I think the write/writenl or show/shownl namas are the best (writeln
instead of writenl is acceptable too, I think).

Spacing problem: I can solve this problem with the solution used in the
Pascal language, that is to not print the space between items. Here are
some examples, from the PrintAsFunction page:

# Standard printing
print 1, 2, 3
shownl(1, " ", 2, " ", 3)

# Printing without any spaces
print "%d%d%d" % (1, 2, 3)
shownl(1, 2, 3)

# Print as comma separated list
print "%d, %d, %d" % (1, 2, 3)
shownl(1, ", ", 2, ", ", 3)

# Print without a trailing newline
print 1, 2, 3,
show(1, " ", 2, " ", 3)

# Print to a different stream
print >> sys.stderr, 1, 2, 3
shownl(1, " ", 2, " ", 3, to=sys.stderr)

# Print a simple sequence
print " ".join(map(str, range(10)))
shownl( " ".join(map(str, range(10))) )

# Print a generator expression
print " ".join(str(x*x) for x in range(10))
shownl( " ".join(str(x*x) for x in range(10)) )
It's not very nice looking, but it's simple, and it avoids problems and
the use of the "sep" parameter. This is the alternative that uses the
sep:

# Print without a trailing newline
print 1, 2, 3,
show(1, 2, 3)

# Printing without any spaces
print "%d%d%d" % (1, 2, 3)
shownl(1, 2, 3, sep='')

# Print as comma separated list
print "%d, %d, %d" % (1, 2, 3)
shownl(1, 2, 3, sep=', ')

# Print a simple sequence
print " ".join(map(str, range(10)))
shownl(*range(10))
I think the % string formatting used in Python can be fine for the C
language (and ), but I have to look its syntax each time I use it ("%"
character + Mapping key (optional) + Conversion flags (optional) +
Minimum field width (optional) + Precision (optional) + Length modifier
(optional) + Conversion type), and I think a simpler solution (fit for
the most common usage) can be found for a high level langage like
Python (I can say something similar about the syntax to define the base
of integer numbers, the use of the trailing 0 for the octals isn't
good).

Bye,
bearophile

Nov 22 '05 #1
0 1762

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Michael Foord | last post by:
Here's a little oddity with 'print' being a reserved word... >>> class thing: pass >>> something = thing() >>> something.print = 3 SyntaxError: invalid syntax >>> print something.__dict__...
14
by: Marcin Ciura | last post by:
Here is a pre-PEP about print that I wrote recently. Please let me know what is the community's opinion on it. Cheers, Marcin PEP: XXX Title: Print Without Intervening Space Version:...
0
by: bearophileHUGS | last post by:
There is/was a long discussion about the replacement for print in Python 3.0 (I don't know if this discussion is finished): http://mail.python.org/pipermail/python-dev/2005-September/055968.html ...
1
by: hamil | last post by:
I am trying to print a graphic file (tif) and also use the PrintPreview control, the PageSetup control, and the Print dialog control. The code attached is a concatination of two examples taken out...
1
by: Steff | last post by:
I am wandering if my code is making sense... I use a lot the print function. Is it weird in this case where I have to display an array ? I thought it would be better to have the entire array in php...
3
by: James J. Besemer | last post by:
I would like to champion a proposed enhancement to Python. I describe the basic idea below, in order to gage community interest. Right now, it's only an idea, and I'm sure there's room for...
69
by: Edward K Ream | last post by:
The pros and cons of making 'print' a function in Python 3.x are well discussed at: http://mail.python.org/pipermail/python-dev/2005-September/056154.html Alas, it appears that the effect of...
2
by: Brad Pears | last post by:
I have some sample code that uses the print dialog, print preview and a print direct options. If I select print preview and then click the printer icon from that, the document prints. If I...
7
by: samslists | last post by:
Am I the only one that thinks this would be useful? :) I'd really like to be able to use python 3.0's print statement in 2.x. Is this at least being considered as an option for 2.6? It seems...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.