def __call__(self, string):
# the special argument "-" means sys.std{in,out}
if string == '-':
if 'r' in self._mode:
return sys.stdin
elif 'w' in self._mode:
return sys.stdout
else:
msg = 'argument "-" with mode %r' % self._mode
raise ValueError(msg)
# all other arguments are used as file names
try:
return open(string,
self._mode,
self._bufsize,
self._encoding,
self._errors,
newline=self._newline)
except OSError as e:
message = "can't open '%s': %s"
raise ArgumentTypeError(message % (string, e))
评论列表
文章目录