Lichen

Annotated lib/__builtins__/io.py

476:7153e60d49b9
2017-01-19 Paul Boddie Added simple import and __file__ attribute test.
paul@6 1
#!/usr/bin/env python
paul@6 2
paul@6 3
"""
paul@6 4
Input/output-related functions.
paul@6 5
paul@173 6
Copyright (C) 2015, 2016 Paul Boddie <paul@boddie.org.uk>
paul@6 7
paul@6 8
This program is free software; you can redistribute it and/or modify it under
paul@6 9
the terms of the GNU General Public License as published by the Free Software
paul@6 10
Foundation; either version 3 of the License, or (at your option) any later
paul@6 11
version.
paul@6 12
paul@6 13
This program is distributed in the hope that it will be useful, but WITHOUT
paul@6 14
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
paul@6 15
FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
paul@6 16
details.
paul@6 17
paul@6 18
You should have received a copy of the GNU General Public License along with
paul@6 19
this program.  If not, see <http://www.gnu.org/licenses/>.
paul@6 20
"""
paul@6 21
paul@435 22
from sys import lstdin, stdout
paul@435 23
paul@347 24
open = file
paul@173 25
paul@435 26
def raw_input(prompt=None):
paul@435 27
paul@435 28
    """
paul@435 29
    Write any specified 'prompt' to standard output and read text from standard
paul@435 30
    input.
paul@435 31
    """
paul@435 32
paul@435 33
    if prompt:
paul@435 34
        stdout.write(prompt)
paul@436 35
        stdout.flush()
paul@435 36
paul@435 37
    return lstdin.readline()
paul@6 38
paul@173 39
def print_(dest, args, nl):
paul@173 40
paul@173 41
    """
paul@173 42
    Write to 'dest' the string representation of 'args', adding a newline if
paul@173 43
    'nl' is given as a true value.
paul@173 44
    """
paul@173 45
paul@173 46
    # Write to standard output if dest is not specified.
paul@173 47
paul@173 48
    dest = dest or stdout
paul@173 49
paul@173 50
    first = True
paul@173 51
paul@173 52
    for arg in args:
paul@173 53
paul@173 54
        # Insert spaces between arguments.
paul@173 55
paul@173 56
        if first:
paul@173 57
            first = False
paul@173 58
        else:
paul@173 59
            dest.write(" ")
paul@173 60
paul@173 61
        dest.write(str(arg))
paul@173 62
paul@173 63
    # Add a newline if specified.
paul@173 64
paul@173 65
    if nl:
paul@173 66
        dest.write("\n")
paul@173 67
paul@6 68
# vim: tabstop=4 expandtab shiftwidth=4