argparse epilog call function?

Chris Angelico rosuav at gmail.com
Tue Jun 27 10:11:13 EDT 2017


On Tue, Jun 27, 2017 at 11:55 PM, Didymus <lynto28 at gmail.com> wrote:
> Greetings,
>
> I might be barking up the wrong tree, but was wondering if there's a way to have the argpasre epilog call a function. for example:
>
> epilog=Examples()
>
> Where Examples is:
>
> def Examples():
>     text = """Lots of examples"""
>     print(text.format())
>
> I've place this in and found that it prints out no matter if I use the -h or
> not and also it prints first.... If I do:
>
> epilog='Single Example'
>
> it works as intended, unfortunately, I need to show several examples. Just wondering if someone has found a why to do this (without making a custom help).

The way you've written it, Examples() will be called before argparse
does its work, and whatever it returns becomes the epilog. Can you
work your function such that it returns a string, instead of printing
something? Or is it a very expensive function?

ChrisA



More information about the Python-list mailing list