Last active
August 29, 2015 14:10
-
-
Save bryder/d1c981bd60e9657a594c to your computer and use it in GitHub Desktop.
short ways to do file I/O in python
This file contains hidden or 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
sys.stderr.write(open("/tmp/filename").read()) | |
cmdline = open("/proc/cmdline").read() | |
with open("/dev/blah","r") as f: | |
for l in f: # l in f means read each line | |
print l | |
try: | |
with open(FILENAME, 'w') as f: | |
f.write(STUFF_TO_WRITE) | |
except Exception as e: | |
log.error("Could not write to %s because %s" % str(FILENAME, e)) | |
sys.exit(-1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment