autoprogram icon indicating copy to clipboard operation
autoprogram copied to clipboard

argparse after `__name__ == "__main__"`

Open raffienficiaud opened this issue 1 year ago • 3 comments

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,

raffienficiaud avatar Oct 30 '23 11:10 raffienficiaud

I have the same problem.

tobeycarman avatar Nov 07 '23 22:11 tobeycarman

@raffienficiaud did you get any further ideas how to solve this?

LongnoseRob avatar Apr 30 '24 08:04 LongnoseRob

@LongnoseRob sorry no, could not find a way to work around it. It should not be too difficult though, the code for getting the parser object seems to be this one but one needs to dig in.

raffienficiaud avatar May 02 '24 19:05 raffienficiaud