Advertisement
Guest User

Untitled

a guest
Jul 24th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.66 KB | None | 0 0
  1. dir = "/storage/emulated/0/a.txt"
  2.  
  3. #ini pendefinisian tanpa menggunakan class
  4. #Buka file txt
  5. def infoPath(path):
  6.     return path
  7.    
  8. def openPath(path):
  9.     for isi_file in open(path).readlines():
  10.         print isi_file
  11.  
  12. print infoPath(dir)
  13. openPath(dir)
  14.  
  15. #dalam class
  16. class openfile:
  17.     def __init__(self, fileku): #constructor class (Membuat parameter class)
  18.         self.file = fileku
  19.  
  20.     def openPath(self):
  21.         return self.file
  22.        
  23.     def openFile(self):
  24.         for isi in open(self.file).readlines():
  25.             print isi
  26.  
  27. op = openfile(dir)
  28. print op.openPath
  29. op.openFile(dir)
  30.  
  31. #pembuatan class sangat efektif
  32. #dalam pembuatan project selanjutnya, menggunakan metode yang sama
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement