I am trying to use memory_profiler , but I ran into a problem that is isolated in example.py:
#! /usr/bin/env python import argparse def parse_args(): parser = argparse.ArgumentParser(description='Dummy description') parser.add_argument('--option', action='store_true') return parser.parse_args() if __name__ == '__main__': parse_args()
So basically use argparse. Standalone this works fine (I have Python3.3). However, when I release
$ python -m memory_profiler example.py
I get an error:
NameError: global name 'argparse' is not defined
Also, if I put a line
parser = argparse.ArgumentParser(description='Dummy description')
Under
if __name__ == '__main__':
And I will comment on the function call for parse_args (), then I do not get the error.
Does anyone know what's wrong here?
source share