MCPcopy Create free account
hub / github.com/ipython/ipython / __init__

Method __init__

IPython/utils/io.py:109–132  ·  view source on GitHub ↗

Construct a new Tee object. Parameters ---------- file_or_name : filename or open filehandle (writable) File that will be duplicated mode : optional, valid mode for open(). If a filename was give, open with this mode. channel : str, one

(self, file_or_name, mode="w", channel='stdout')

Source from the content-addressed store, hash-verified

107 # http://mail.python.org/pipermail/python-list/2007-May/442737.html
108
109 def __init__(self, file_or_name, mode="w", channel='stdout'):
110 """Construct a new Tee object.
111
112 Parameters
113 ----------
114 file_or_name : filename or open filehandle (writable)
115 File that will be duplicated
116
117 mode : optional, valid mode for open().
118 If a filename was give, open with this mode.
119
120 channel : str, one of ['stdout', 'stderr']
121 """
122 if channel not in ['stdout', 'stderr']:
123 raise ValueError('Invalid channel spec %s' % channel)
124
125 if hasattr(file_or_name, 'write') and hasattr(file_or_name, 'seek'):
126 self.file = file_or_name
127 else:
128 self.file = open(file_or_name, mode)
129 self.channel = channel
130 self.ostream = getattr(sys, channel)
131 setattr(sys, channel, self)
132 self._closed = False
133
134 def close(self):
135 """Close the file and restore the channel."""

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected