Skip to content
Snippets Groups Projects
Commit dc13dab9 authored by Nada Afra's avatar Nada Afra
Browse files

basic_storage_class

parent 2e2013e4
2 merge requests!2Storage,!1Storage
Pipeline #16292 canceled with stages
import time
class Storage :
setdata = {}
def __init__(self):
data = {
"value" : 0,
"timestamp" : 0
}
#global setdata
for i in range (10000):
self.write(i,0,0)
def write(self,key, val, trans_id):
newdata = {
"value" : val,
"timestamp" : time.time()
}
self.setdata[key] = newdata
def read(self, key, trans_id):
#return value kalo key ada, kalo gak return false
hasil = self.setdata.get(key,False)
print(hasil)
if (hasil) :
value = hasil["value"]
return value
else :
return False
def timestamp(self, key):
hasil = self.setdata.get(key,False)
if (hasil) :
time = hasil["timestamp"]
return time
else :
return 0
#def read()
S = Storage()
#print(S.setdata)
value = 0
tis =S.read(100,value,1)
print(tis)
tes =S.read(1000001,value,1)
print(tes)
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment