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