Skip to content

argparse after __name__ == "__main__" #66

@raffienficiaud

Description

@raffienficiaud

Dear autoprogram team,

If I have a code like this:

if __name__ == "__main__":
    logger.setLevel("DEBUG")

    parser = argparse.ArgumentParser(
        description="""random"""
    )

then the autoprogram is unable to see the parser object for that specific file. Moving parser up before the if works, but require all the add_argument to be above the if __name__ == "__main__".

I usually declare the parser only if this is executed as a script or with the -m option of python, and tend to avoid global objects otherwise.

Is there a way to make it work like this?

Thank you,

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions