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