Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Random Python Feature
#1
I'm working on an interface where the user selects functions. But some of those functions are meta-functions that create the function you want. But the meta-functions can have different types of parameters. How do I validate them? The parameter names are pretty consistent, so I can base the validation off the parameter names. But how do I get the parameter names?

Now, because of the way I write my docstrings, I could write something to parse func.__doc__ and return the parameter names. But is there a way to get that information straight from the function object? It turns out there is:

func.__code__.co_varnames[:func.__code__.co_argcount]
I love Python.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
Random Python Feature - by ichabod801 - Aug-25-2019, 02:50 PM
RE: Random Python Feature - by snippsat - Aug-25-2019, 04:35 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  a feature i would like to see added to Python Skaperen 0 615 Oct-30-2023, 12:30 AM
Last Post: Skaperen
  Can the video calling feature be used from python telegram bot api? Kumarkv 0 1,939 May-30-2020, 01:34 PM
Last Post: Kumarkv
  Python in Feature film Larz60+ 0 3,212 Dec-11-2016, 02:17 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020