473,854 Members | 1,491 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(1 0))
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 1838

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

Similar topics

12
2414
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
2924
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: $Revision: 0.0 $
0
877
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 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...
1
5726
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 of a Microsoft book, "Visual Basic,Net Step by Step" in Chapter 18. All but the bottom two subroutines will open a text file, and then allow me to use the above controls, example 1. The bottom two subroutines will print a graphic file, example...
1
2329
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 but now I am not sure if that makes sense. Can you tell me please ? <html> <head>
3
2115
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 improvement. And of course it's possible there's some serious "gotcha" I've overlooked. Thus I welcome any and all comments. If there's some agreement that this proposal is worth further consideration then I'll re-submit a formal document in...
69
3235
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 this pep would be to make it impossible to use the name 'print' in a backward compatible manner. Indeed, if a program is to compile in both Python 2.x and Python 3.x, the print function (or the print statement with parentheses) can not use the...
2
22136
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 select the print directly option, it also prints right away to the defauilt printer. However, if I use the printer dialog control to print and I click 'OK' to actually print the document - nothing happens. The job does not even go into the print...
7
10765
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 like it would be helpful with transitioning.
0
9901
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9751
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10675
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10367
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9512
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7079
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5740
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5939
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4556
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.