ANN: PyStream - a C++ stream emulation
Andreas Jung
andreas at andreas-jung.com
Tue Aug 22 14:56:48 EDT 2000
Have you ever dreamt of using C++ streams inside Python ?
Well here is your solution:
PyStream - A C++ stream emulation for Python
--------------------------------------------
PyStream is a trial to emulate most of the C++ stream functionality
in Python. PyStream offers classes to support input and output
streams using the C++ notation with the shift operators << and >>.
Output streams:
---------------
PyStream provide a metaclass ostream that should not be instanciated
directly. Instead use one of the following predefined classes:
StrOStream() creates an ostream. The stream is written to an internal
StringIO() instance.
FileOStream(fname,fp) creates a file like ostream. The constructor either
take the name of a file to write the stream or an
open Python file handle. In case when no arguments are
used sys.stdin is used as output file handle.
Manipulators:
-------------
PyStream provides a nearly complete set of all C++ stream manipulators:
endl
ends
_hex
_dec
_oct
_boolalpha
_noboolalpha
_flush
fixed
scientific
setprecision
uppercase
nouppercase
setw
setfill
For some reasons it has been neccessary to prefix some of the known C++ manipulators
with _ because of naming conflicts with predefined python methods.
Example:
--------
from ostream import *
from manipulator import *
import math
num = math.pi
x=FileOstream()
x << hex <<16 << endl;
for x in [FileOstream(),FileOstream('sux.out')]:
for p in range(0,5):
x << setprecision(p) << "Precision: " << x.precision() << " " << num << endl;
for p in range(0,15):
x <<setw(20) << setprecision(p) << setfill('%') << uppercase << num << setfill(' ') << num << endl;
Input streams:
--------------
The meta class for all input stream is "istream". At the moment there
is just on subclass for reading a stream from a file:
FileIStream(fname,fp) see FileOStream() for the further details
Current Version: 0.1
----------------
Download from: http://www.suxers.de/PyStream.tar.gz
--------------
------------------------------------------------------------------------
Author of PyStream: Andreas Jung, ajung at suxers.de
This software is published under the BSD license.
More information about the Python-list
mailing list