daily pastebin goal
81%
SHARE
TWEET

Length read tests

a guest May 24th, 2018 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def read_tests(mode):
  2.     with open("Myfile1.txt", mode="r", encoding="utf-8") as Fileobj:
  3.         if mode == "read":
  4.             data = Fileobj.read()
  5.         elif mode == "readline":
  6.             data = Fileobj.readline()
  7.         else:
  8.             data = Fileobj.readlines()
  9.         print("{0}[{1}]: \n{2}".format(mode.upper(), len(data), data))
  10.  
  11.  
  12. def main():
  13.     read_modes = "read readline readlines".split()
  14.     sep = "-" * 20
  15.     for mode in read_modes:
  16.         print(sep)
  17.         read_tests(mode)
  18.     print(sep)
  19.     print("File Read Successfully")
  20.  
  21.  
  22. if __name__ == "__main__":
  23.     main()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top