Posted By

zhxiangxie on 11/02/15


Tagged

python


Versions (?)

SyncProc


 / Published in: Python
 

test sync

  1. import sys
  2.  
  3. class User:
  4. name = ""
  5. age = 0
  6. height = 0
  7. weight = 0
  8.  
  9. def display(self):
  10. print ''
  11. print 'User Information:'
  12. print 'User Name :', self.name
  13. print 'User Age :', self.age
  14. print 'User Height:', self.height
  15. print 'User Weight:', self.weight
  16.  
  17. def loadFromInput(self):
  18. self.name = raw_input('Enter User Name: ')
  19. self.age = int(raw_input('Enter Age: '))
  20. self.height = float(raw_input('Enter Height (in feet): '))
  21. self.weight = int(raw_input('Enter Weight: '))
  22.  
  23. def save(self):
  24. f = open('user.info','w')
  25. f.write(self.name + '\n')
  26. f.write(str(self.age) + '\n')
  27. f.write(str(self.height) + '\n')
  28. f.write(str(self.weight) + '\n')
  29. f.close()
  30.  
  31. def loadFromFile(self):
  32. f = open('user.info', 'r')
  33. self.name = f.readline().rstrip()
  34. self.age = int(f.readline())
  35. self.height = float(f.readline())
  36. self.weight = int(f.readline())
  37.  
  38.  
  39. theUser = None
  40.  
  41. if len(sys.argv) > 1 and sys.argv[1] == 'READ':
  42. theUser = User()
  43. theUser.loadFromFile()
  44. else:
  45. theUser = User()
  46. theUser.loadFromInput()
  47. theUser.save()
  48.  
  49. theUser.display()

Report this snippet  

You need to login to post a comment.