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 open = file 23 24 def raw_input(prompt=None): pass 25 26 def print_(dest, args, nl): 27 28 """ 29 Write to 'dest' the string representation of 'args', adding a newline if 30 'nl' is given as a true value. 31 """ 32 33 # If imported at the module level, the sys module must be set up first, 34 # which should be ensured by the module ordering activity, and a module 35 # attribute will be employed to hold a reference to sys.stdout. 36 37 from sys import stdout 38 39 # Write to standard output if dest is not specified. 40 41 dest = dest or stdout 42 43 first = True 44 45 for arg in args: 46 47 # Insert spaces between arguments. 48 49 if first: 50 first = False 51 else: 52 dest.write(" ") 53 54 dest.write(str(arg)) 55 56 # Add a newline if specified. 57 58 if nl: 59 dest.write("\n") 60 61 # vim: tabstop=4 expandtab shiftwidth=4