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 <[email protected]>: > 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 > [email protected] > https://mail.python.org/mailman/listinfo/python-nl >
_______________________________________________ Python-nl mailing list [email protected] https://mail.python.org/mailman/listinfo/python-nl
