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