Skip to content

Instantly share code, notes, and snippets.

@Squab
Created January 10, 2015 21:13
Show Gist options
  • Save Squab/d4190acdcacb56c918dc to your computer and use it in GitHub Desktop.
Save Squab/d4190acdcacb56c918dc to your computer and use it in GitHub Desktop.
Make a Python script behave like a Linux command (take a filename or stdin)
import sys
if __name__ == "__main__":
f = None
try:
filename = sys.argv[1]
f = open(filename, 'r')
except IndexError:
f = sys.stdin.readlines()
for line in f:
print line,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment