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 def open(name, mode=None, buffering=None): 23 24 """ 25 Open the file with the given 'name', using the given 'mode' and applying the 26 indicated 'buffering'. 27 """ 28 29 return file(name, mode, buffering) 30 31 def raw_input(prompt=None): pass 32 33 def print_(dest, args, nl): 34 35 """ 36 Write to 'dest' the string representation of 'args', adding a newline if 37 'nl' is given as a true value. 38 """ 39 40 # If imported at the module level, the sys module must be set up first, 41 # which should be ensured by the module ordering activity, and a module 42 # attribute will be employed to hold a reference to sys.stdout. 43 44 from sys import stdout 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 68 # vim: tabstop=4 expandtab shiftwidth=4