cat.py 487 B

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