Created
March 26, 2013 11:18
-
-
Save timtan/5244685 to your computer and use it in GitHub Desktop.
get content no matter the file exists
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
__author__ = 'tim' | |
def read_content(name): # just print an message indicate error | |
''' | |
it is of if the file is not exist | |
''' | |
try: | |
fs = open(name) | |
print "coder after error will not printed" | |
return fs.read() | |
except IOError as error: | |
return '' | |
if __name__ == '__main__': | |
result = read_content('foo.txt') | |
print 'result is :', result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment