Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- dir = "/storage/emulated/0/a.txt"
- #ini pendefinisian tanpa menggunakan class
- #Buka file txt
- def infoPath(path):
- return path
- def openPath(path):
- for isi_file in open(path).readlines():
- print isi_file
- print infoPath(dir)
- openPath(dir)
- #dalam class
- class openfile:
- def __init__(self, fileku): #constructor class (Membuat parameter class)
- self.file = fileku
- def openPath(self):
- return self.file
- def openFile(self):
- for isi in open(self.file).readlines():
- print isi
- op = openfile(dir)
- print op.openPath
- op.openFile(dir)
- #pembuatan class sangat efektif
- #dalam pembuatan project selanjutnya, menggunakan metode yang sama
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement