-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathReadingFrom1010Files.py
More file actions
39 lines (28 loc) Β· 862 Bytes
/
ReadingFrom1010Files.py
File metadata and controls
39 lines (28 loc) Β· 862 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#to serialize an object we must import a libary called pickle
import pickle
class Nelan(object):
name=" "
age= 0
def __init__(self, name="notknown"):
self.name=name
def hello(self):
print("\nHello There Everyone my name is %s" %self.name)
#how to store to disk and pull it up later aka object serialization
#We create a file and it gets serialized to the disk
#Let's see if the object works fine
neha=Nelan()
neha.name="Nelan"
neha.age=24
neha.hello()
#Write to a file
wrtofile=r"/home/test.txt"
with open(wrtofile, "bw") as d:
pickle.dump(neha,d)
print("The plane has landed at Nelan Island")
#Now I read that file back in and load it
with open(wrtofile,"br") as d:
m=pickle.load(d)
print(m)
#isinstance takes object as 1st param and className as 2nd Param
if isinstance(d,Nelan):
print(Nelan.age)