Close a file after using,closeusing,import sys
Close a file after using,closeusing,import sys
import sys def 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_filedef next_line(the_file): '''Return next line from the trivia file, formatted.''' line = the_file.readline() line = line.replace('/', '\n') return linetrivia_file = open_file('trivia.txt', 'r')title = next_line(trivia_file)trivia_file.close()
- Difference between a normal function and a lambda functi
- Introducing ljust,introducingljust,s = 'buildCo
- Used by print: user-friendly form,useduser-friendly,nu
- Compute prime numbers in Python,computeprime,nums = ra
- 5 threads, each sleeps 3 second in parallel,threadssle
- Split a string by ',',splitstringby,li
热门文章:
相关内容
- Difference between a normal function and a lambda function,differen
- Introducing ljust,introducingljust,s = 'buildCo
- Used by print: user-friendly form,useduser-friendly,num = 1 / 3.
- Compute prime numbers in Python,computeprime,nums = range
- 5 threads, each sleeps 3 second in parallel,threadssleeps,import th
- Split a string by ',',splitstringby,line = 'bob,
- Checkbutton to set font to bold,checkbuttonbold,from Tkinter
- Draw lines,drawlines,from Tkinter
- Line width,linewidth,from Tkinter
- Adding Elements to Lists,addinglists,li = ['a', '
评论关闭