wasm-demo/demo/ermis-f/python_m/cur/0524

64 lines
1.7 KiB
Plaintext

From: sdm7g at Virginia.EDU (Steven D. Majewski)
Date: Thu, 22 Apr 1999 20:54:13 -0400 (EDT)
Subject: Emulating C++ coding style
In-Reply-To: <slrn7hvbbu.bmd.wtanksle@dolphin.openprojects.net>
References: <371F8FB7.92CE674F@pk.highway.ne.jp> <slrn7hvbbu.bmd.wtanksle@dolphin.openprojects.net>
Message-ID: <Pine.A32.3.90.990422204838.15765A-100000@elvis.med.Virginia.EDU>
Content-Length: 1266
X-UID: 524
On Fri, 23 Apr 1999 06:08:07 +0900, Thooney Millennier asked about
Python equivalents to C++ code.
>
> >2. stream class
> > e.g. cout << "hello python."<<endl;
On Thu, 22 Apr 1999, William Tanksley replied:
> VERY bad idea. Bad even in C++.
>
> sys.stdout.write("hello python." + "\n");
However, if you *REALLY* want to have that sort of C++ syntax,
you can get it in Python with something like:
endl = '\n'
class OutStream:
def __init__( self, file ):
if hasattr( file, 'write' ):
self.file = file
else:
self.file = open( file, 'w' )
def write( self, what ):
self.file.write( what )
def close( self ):
self.file.close()
def __lshift__(self, what ):
self.write( str(what)+' ')
return self
import sys
out = OutStream( sys.stdout )
out << "Hello" << "World" << endl
out << "The answer is" << 3+4 << endl
---| Steven D. Majewski (804-982-0831) <sdm7g at Virginia.EDU> |---
---| Department of Molecular Physiology and Biological Physics |---
---| University of Virginia Health Sciences Center |---
---| P.O. Box 10011 Charlottesville, VA 22906-0011 |---
Caldera Open Linux: "Powerful and easy to use!" -- Microsoft(*)
(*) <http://www.pathfinder.com/fortune/1999/03/01/mic.html>