Code: writeln.py for playing

Mike Fletcher mfletch at tpresence.com
Wed Aug 30 05:49:54 EDT 2000


Figured I should make this code a little more useful for those interested in
playing with Py3K ideas, and since nothing's showing up on the newsgroup,
some may have missed the whole discussion...

8<____ writeln.py ____________________
'''Quick module showing writeln ideas'''

import sys, string
def writeln( *args, **namedargs ): # untested pseudo-code
	if namedargs.has_key( "file" ):
		file = namedargs["file"]
		if file is None:
			file = sys.stdout
	else:
		file = sys.stdout
	output = string.join( map(str, args), ' ')
	file.write( output)
	end = namedargs.get( "end", '\n' )
	if end:
		file.write( end )

if __name__ == "__main__":
	writeln( "this", "is", "a", "test" )
	writeln( "no newline, no space", end="")
	writeln( "more on same line" )
	have = "HAVE"
	writeln( "what", have, "you", "done! space _and_ newline?", end="
\n")
	writeln( "to stderr", file = sys.stderr )
	writeln( "to stderr no newline, no space", end="", file = sys.stderr
)

Of course, it's usable in current Python versions, you just do 

	import writeln
	__builtins__.writeln = writeln.writeln

In your site.py (or wherever) and you can try it out in your code.

Enjoy,
Mike


-----Original Message-----
From: Guido van Rossum [mailto:guido at beopen.com]
Sent: Saturday, August 26, 2000 11:01 PM
To: Mike Fletcher
Cc: python-list at python.org
Subject: Re: gratuitous new features in 2.0


[Didn't see this on usenet yet, responding to the mail.]
...
> writeln as builtin function:
...
This is all good stuff for a redesign for Python 3000.  I'm inclined
to at least *look* into making print a function in Py3k -- then we can
look into how to make it easy to use, etc.

For Py2.x, that's all too much work, and hence everybody who still
suggests to use a function for the extra functionality should re-read
my previous post.
...
As long as we're discussing this potential Py3k design, I'd rather
have separate methods, e.g. writeln(item, ...) and writesp(item, ...).

--Guido van Rossum (home page: http://www.pythonlabs.com/~guido/)
...




More information about the Python-list mailing list