473,396 Members | 1,982 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 855

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...
12
by: Studiotyphoon | last post by:
Hi, I have report which I need to print 3 times, but would like to have the following headings Customer Copy - Print 1 Accounts Copy - Print 2 File Copy -Print 3 I created a macro to...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.