Python "aha" moment

Guy Middleton guy at obstruction.com
Thu Jun 10 02:49:35 CEST 2004


I wanted to decode some MIME base64 text, and had no program that does this,
so I thought it must be easy to do in Python.

I have been using Python, on and off, for a long time, so I used a file idiom
I remembered from years ago:

	for line in sys.stdin:
		sys.stdout.write(base64.decodestring(line))


This works fine, but then I realised that the language has evolved since then,
and I could make this more obviously a transformation:

	base64.decode(sys.stdin, sys.stdout)


I like this version much better.



More information about the Python-list mailing list