Jan-20-2018, 09:16 PM
(This post was last modified: Jan-20-2018, 09:16 PM by Gribouillis.)
If you want to access the parameter names of a function or the local variables defined in this function, the correct way is to use module inspect and attributes of code objects, for example:
>>> import inspect >>> def spam(a, b, c='foo'): ... bar = a + c ... qux = [x for x in b if x.is_baz()] ... >>> spam.__code__.co_varnames ('a', 'b', 'c', 'bar', 'qux') >>> s = inspect.signature(spam) >>> s.parameters mappingproxy(OrderedDict([('a', <Parameter "a">), ('b', <Parameter "b">), ('c', <Parameter "c='foo'">)]))