Skip to content
This repository has been archived by the owner on Nov 25, 2021. It is now read-only.

How to introduce a variable in insert_before? #4

Open
sachinhub opened this issue Jun 6, 2018 · 0 comments
Open

How to introduce a variable in insert_before? #4

sachinhub opened this issue Jun 6, 2018 · 0 comments

Comments

@sachinhub
Copy link

Trying to log time taken by a method. So want to store the time.time() in a variable in insert_before() and print the time taken in the insert_after () as follows -

MY_BEFORE_CODE = '__t1 = time.time(); print ("PERF LOG -START-'+ meth_decl.method_name +'", t1)'
MY_AFTER_CODE = 'print ("PERF LOG -END-'+ meth_decl.method_name +'", time.time() - t1)'

rewriter.insert_before(MY_BEFORE_CODE)
rewriter.insert_after(MY_AFTER_CODE)

getting following error -

SystemError: no locals found when storing '__t1'

Any pointers?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant