本文整理汇总了Python中cache.Cache.read_address方法的典型用法代码示例。如果您正苦于以下问题:Python Cache.read_address方法的具体用法?Python Cache.read_address怎么用?Python Cache.read_address使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cache.Cache
的用法示例。
在下文中一共展示了Cache.read_address方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Cmd
# 需要导入模块: from cache import Cache [as 别名]
# 或者: from cache.Cache import read_address [as 别名]
class Cmd(object):
def __init__(self):
self.cache = Cache()
def get_address(self, statement):
address = raw_input("What address would you like {}?\n".format(statement))
return address
def get_action(self):
action = raw_input("(R)ead, (W)rite, or (D)isplay Cache?\n")
if action is '':
action = 'q'
return action.lower()[0]
def read_address(self, address):
result = self.cache.read_address(address)
print "At that byte there is the value {0:X} ({1})".format(result[0],
result[1])
return
def write_data(self, address):
datum = raw_input("What datum would you like to write at that address?\n")
datum = int(datum, 16)
result = self.cache.write_address(address, datum)
print ("Value {:X} has been written to address {:X}. ({})".format(
datum,
address,
result))
return
def display_cache(self):
print str(self.cache)
return
def run(self):
while True:
action = self.get_action()
if action == "r":
address = int(self.get_address("read"), 16)
self.read_address(address)
elif action == "w":
address = int(self.get_address("to write to"), 16)
self.write_data(address)
elif action == "d":
self.display_cache()
else:
break
return