cat.py 537 B

12345678910111213141516171819
  1. #!/usr/bin/env python
  2. import sys
  3. from shutil import copyfileobj as copy
  4. import os.path
  5. PY3 = sys.version_info[0] == 3
  6. if __name__ == '__main__':
  7. for filename in sys.argv[1:] or ["-"]:
  8. if filename == "-":
  9. copy(sys.stdin, sys.stdout)
  10. else:
  11. if os.path.exists(filename):
  12. with open(filename, 'r' if PY3 else 'rb') as file:
  13. copy(file, sys.stdout)
  14. else:
  15. sys.stderr.write('cat.py: {0}: No such file or directory\n'.format(filename))