Skip to content

Instantly share code, notes, and snippets.

@timtan
Created March 26, 2013 11:18
Show Gist options
  • Save timtan/5244685 to your computer and use it in GitHub Desktop.
Save timtan/5244685 to your computer and use it in GitHub Desktop.
get content no matter the file exists
__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