Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/allpy/rev/927085d03977
Дата изменения: Unknown
Дата индексирования: Tue Oct 2 01:04:00 2012
Кодировка:
allpy: 927085d03977

allpy

changeset 862:927085d03977

Added allpy.util.open(), a wrapper around open(), which allows "-" as a filename to signify stdin or stdout
author Daniil Alexeyevsky <dendik@kodomo.fbb.msu.ru>
date Thu, 21 Jul 2011 18:29:42 +0400
parents 0dbbf6403b7f
children ddf85d0a8924
files allpy/util.py
diffstat 1 files changed, 12 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- a/allpy/util.py	Thu Jul 21 16:41:08 2011 +0400
     1.2 +++ b/allpy/util.py	Thu Jul 21 18:29:42 2011 +0400
     1.3 @@ -1,5 +1,6 @@
     1.4  """Miscellanous utilities.
     1.5  """
     1.6 +import sys
     1.7  import warnings
     1.8  
     1.9  def unzip(seq):
    1.10 @@ -10,6 +11,17 @@
    1.11          b.append(y)
    1.12      return a, b
    1.13  
    1.14 +def open(filename, mode='r'):
    1.15 +    """Open file. Return stdin/stdout for filename '-'."""
    1.16 +    if filename == '-':
    1.17 +        if 'w' in mode or 'a' in mode or '+' in mode:
    1.18 +            return sys.stdout
    1.19 +        if 'r' in mode:
    1.20 +            return sys.stdin
    1.21 +        raise AssertionError("Unknown file mode: %s" % mode)
    1.22 +    else:
    1.23 +        return file(filename, mode)
    1.24 +
    1.25  def remove_each(string, substrings):
    1.26      """Remove each of substrings from string."""
    1.27      for sub in substrings: