Define function to Open a file,definefunction,import sysde
文章由Byrx.net分享于2019-03-23 06:03:36
Define function to Open a file,definefunction,import sysde
import sysdef open_file(file_name, mode): '''Open a file.''' try: the_file = open(file_name, mode) except(IOError), e: print 'Unable to open the file', file_name, 'Ending program.\n', e raw_input('\n\nPress the enter key to exit.') sys.exit() else: return the_filetrivia_file = open_file('trivia.txt', 'r')
相关内容
- Writing to Files,writingtofiles,# Append mod
- Special char output,specialcharoutput,print \'''St
- bitwise AND,bitwiseand,x = 1
- Give the parameters in the function default values,parametersvalues
- Tuple sequence,tuplesequence,X = 'spam'Y
- Reference index in a list in Python.,referencepython,foo = [42, '
- File Wildcards,filewildcards,#The glob mo
- Listing Directories,listingdirectories,import os os
- Echo command line arguments,echoarguments,'''Echo comm
- Data Compression,datacompression,import zlibs
评论关闭