Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

# Write your own version of dis.dis() that produces a dictionary object # containing the following values: # # names: a list of the function's

# Write your own version of dis.dis() that produces a dictionary object

# containing the following values: # # names: a list of the function's names (the .co_varnames attribute) # consts: a list of the function's constants (the .co_consts attribute) # code: a list of the function's bytecode (the .co_code attribute) # instructions: a list of the sequence of instructions for the function. # # Each instruction list has the following four components # # adjusted line number: index position in the bytecode list # instruction opcode number: opcode from the bytecode list # opname: symbolic name for the opcode # index: if the opcode takes an argument, the numeric index value, else None # argument: if the opcode takes an argument, the value of the argument, else None

# makeobj(s1) => # {'instructions': # [(0, 100, 'LOAD_CONST', 1, 1), # (3, 125, 'STORE_FAST', 0, 'a'), # (6, 124, 'LOAD_FAST', 0, 'a'), # (9, 83, 'RETURN_VALUE', None, None)], # 'names': ('a',), # 'code': b'd\x01\x00}\x00\x00|\x00\x00S', # 'consts': (None, 1)}

# Note that makeobj is similar to dis.dis(). You may use dis.dis() # to help test your implementation of makeobj() # # You may also want to use dis.HAVE_ARGUMENT to identify those # opcodes that do and do not take an argument

def makeobj(fun): result = {} names = fun.__code__.co_varnames result['names'] = names consts = fun.__code__.co_consts result['consts'] = consts code = fun.__code__.co_code result['code'] = code codelen = len(code) instructions = [] ## fill in the rest here result['instructions'] = instructions return result

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 24th International Conference Dexa 2013 Prague Czech Republic August 2013 Proceedings Part 1 Lncs 8055

Authors: Hendrik Decker ,Lenka Lhotska ,Sebastian Link ,Josef Basl ,A Min Tjoa

2013 Edition

3642402844, 978-3642402845

More Books

Students also viewed these Databases questions

Question

Explain the steps involved in training programmes.

Answered: 1 week ago

Question

What are the need and importance of training ?

Answered: 1 week ago