1 #!/usr/bin/env python 2 3 """ 4 Input/output-related functions. 5 6 Copyright (C) 2015, 2016, 2017 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 stdout.flush() 36 37 return lstdin.readline() 38 39 def print_(dest, args, nl): 40 41 """ 42 Write to 'dest' the string representation of 'args', adding a newline if 43 'nl' is given as a true value. 44 """ 45 46 # Write to standard output if dest is not specified. 47 48 dest = dest or stdout 49 50 first = True 51 52 for arg in args: 53 54 # Insert spaces between arguments. 55 56 if first: 57 first = False 58 else: 59 dest.write(" ") 60 61 dest.write(str(arg)) 62 63 # Add a newline if specified. 64 65 if nl: 66 dest.write("\n") 67 else: 68 dest.write(" ") 69 70 # vim: tabstop=4 expandtab shiftwidth=4