Python Forum
list of user's variables in the interpreter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
list of user's variables in the interpreter
#3
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'">)]))
Reply


Messages In This Thread
RE: list of user's variables in the interpreter - by Gribouillis - Jan-20-2018, 09:16 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Advancing Through Variables In A List knight2000 0 573 May-13-2023, 03:30 AM
Last Post: knight2000
  user input values into list of lists tauros73 3 1,216 Dec-29-2022, 05:54 PM
Last Post: deanhystad
  functional LEDs in an array or list? // RPi user Doczu 5 1,816 Aug-23-2022, 05:37 PM
Last Post: Yoriz
  User-defined function to reset variables? Mark17 3 1,798 May-25-2022, 07:22 PM
Last Post: Gribouillis
  WHILE Loop - constant variables NOT working with user input boundaries C0D3R 4 1,611 Apr-05-2022, 06:18 AM
Last Post: C0D3R
  Setting permanent user variables in Windows coder420 2 1,501 Jan-04-2022, 10:42 AM
Last Post: Larz60+
  Looking for a way to loop until user enters from a list? PythonW19 7 3,581 Mar-21-2021, 08:56 PM
Last Post: PythonW19
  User input/picking from a list AnunnakiKungFu 2 2,433 Feb-27-2021, 12:10 AM
Last Post: BashBedlam
Question Reset list if user regrets Gilush 1 2,144 Dec-05-2020, 10:55 AM
Last Post: Gilush
  Converting list to variables Palves 1 1,852 Sep-18-2020, 05:43 PM
Last Post: stullis

Forum Jump:

User Panel Messages

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