Advertisement
maincarry

CS-PreRelease_Task32.py

May 15th, 2016
424
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.33 KB | None | 0 0
  1. '''
  2. Task 3.2
  3. By Mark Wu
  4. @markwu.me
  5. '''
  6.  
  7. # import os
  8.  
  9.  
  10. # -----------------Welcome screen-----------------
  11. print("-----------------Task 3.2-----------------")
  12. print('''
  13.  
  14. -----Task 3 Overview-----
  15. [1] (Task 3.1) Create new records
  16. [2] (-----SELECTED-----) See current records
  17. [3] (Task 3.3) Find member ID
  18. [4] (Task 3.4) Add new users
  19. ''')
  20.  
  21.  
  22. # -----------------Task 3.2-----------------
  23.  
  24. # The following are the functions used in the program
  25.  
  26.  
  27.  
  28. # Initialization
  29. member_list = [] # List
  30.  
  31. # Check if file exists:
  32. # file_found = os.path.isfile('record.txt') # Boolean
  33. file_found = True # Can't do this validation because I can't import
  34. if file_found:
  35.     try:
  36.         with open('record.txt') as myfile:
  37.             content = myfile.readlines()
  38.             for each in content:
  39.                 each_member = each.split(',')
  40.                 each_member[1] = each_member[1].strip() # remove line breakers
  41.                 each_member[0] = each_member[0].ljust(25) # fill up to 25 characters for column neatness
  42.                 member_list.append(each_member)
  43.     except:
  44.         print("Invalid record format.")
  45.     else:
  46.         print('''
  47. --------Current Record--------
  48. Name                   Member ID
  49. ''')
  50.         for each in member_list:
  51.             print(each[0] + each[1])
  52.  
  53.  
  54. else:
  55.     print("File not exist!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement