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

How to introduce a variable in insert_before? #4

Description

@sachinhub

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions