Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

argparse after __name__ == "__main__" #66

Open
raffienficiaud opened this issue Oct 30, 2023 · 3 comments
Open

argparse after __name__ == "__main__" #66

raffienficiaud opened this issue Oct 30, 2023 · 3 comments

Comments

@raffienficiaud
Copy link

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,

@tobeycarman
Copy link

I have the same problem.

@LongnoseRob
Copy link

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

@raffienficiaud
Copy link
Author

@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.

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

No branches or pull requests

3 participants