Created
November 28, 2012 14:46
-
-
Save fyears/4161739 to your computer and use it in GitHub Desktop.
python stdin example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
''' | |
usage: | |
cat about.txt | python soinput.py | |
''' | |
import sys | |
def read_in(): | |
lines = sys.stdin.readlines() | |
for i in range(len(lines)): | |
lines[i] = lines[i].replace('\n','') | |
#print lines | |
return lines | |
def main(): | |
lines = read_in() | |
print lines | |
if __name__ == '__main__': | |
main() |
Most likely you don't want to remove all whitespace from the line, only the trailing newline
def read_in():
return [x.rstrip('\n') for x in sys.stdin ]
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the gist! I've used it to set up an alias to urlencode strings like so, maybe this is helpful to someone: