Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- #s3my0n
- def print_files(files_number=2):
- files = []
- for i in xrange(files_number):
- try:
- a = raw_input('\nEnter file %d: '%(i+1))
- fopen = open(a, 'r')
- except IOError:
- print '\nCould not open file %s'%(a)
- exit(1)
- except KeyboardInterrupt:
- print '\nAborted: exiting'
- exit(1)
- else:
- files.append(fopen)
- for i in files:
- print '\n%s\n%s%s' % ('-'*50, i.read(), '-'*50)
- def ask_for_files_number():
- while True:
- try:
- number = int(raw_input("\nPlease enter the number of files to read: "))
- except ValueError:
- print '\nNeed a valid number'
- continue
- except KeyboardInterrupt:
- print '\nAborted'
- exit(1)
- else:
- return number
- if __name__ == '__main__':
- print_files() # initial print
- while True:
- try:
- choice = raw_input("\nWould you like to read more files? Enter 1 for yes or 2 for no: ").lower()
- except KeyboardInterrupt:
- print '\nAborted'
- exit(1)
- else:
- if choice in ('1', 'yes'):
- n = ask_for_files_number()
- print_files(n)
- elif choice in ('2', 'no'):
- print 'Good bye'
- exit(0)
- else:
- print 'Please enter a valid choice (1/yes, 2/no)'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement