[python-nl] Doc string van een andere functie
Douwe van der Meij
douwe at karibu-online.nl
Thu Mar 9 16:56:27 EST 2017
Wel een typo zie ik in mijn comment: eval is *niet* zo mooi in je code..
Maar goed, het werkt wel..
w: www.karibu-online.nl
m: 06 5060 4033
Op 9 maart 2017 om 22:54 schreef Geert Stappers <stappers at stappers.nl>:
> On Thu, Mar 09, 2017 at 10:46:57PM +0100, Douwe van der Meij wrote:
> > Hoi Geert,
> >
> > *functie3('functie2')* # zoals je hebt
> >
> > en dan:
> >
> > *def functie3(functienaam):*
> > * print(eval(functienaam).__doc__)* # dit werkt altijd, maar eval
> is mooi in je code
>
> Die is gaaf!
>
>
> > of:
> >
> > *def functie3(functienaam):*
> > * print(globals()[functienaam].__doc__)* # dit werkt niet bij
> built-in functies
>
> Werkt ook (voor mijn doel)
>
>
> #!/usr/bin/env python
>
> def functie1():
> """functie die zijn eigen doc string print"""
> print functie1.__doc__
> return
>
> def functie2():
> """functie die doc string van andere functie print"""
> print functie1.__doc__
> return
>
> def functie3(functienaam):
> """ te gebruiken als "help tekst printer." """
> print eval(functienaam).__doc__
> print globals()[functienaam].__doc__
> return
>
> if __name__ == "__main__":
> functie3('functie2')
> # toepassing
> user_input = 'functie2'
> functie3(user_input)
>
> de_gewenste_output = """
> functie die doc string van andere functie print
> functie die doc string van andere functie print
> functie die doc string van andere functie print
> functie die doc string van andere functie print
> """
>
> # l l
>
> Dank je wel
>
> Groeten
> Geert Stappers
> --
> Leven en laten leven
> _______________________________________________
> Python-nl mailing list
> Python-nl at python.org
> https://mail.python.org/mailman/listinfo/python-nl
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-nl/attachments/20170309/50047353/attachment-0001.html>
More information about the Python-nl
mailing list