Python Forum

Full Version: How to access values returned from inquirer
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
1. I'm using the code below and it works well.
I'm able to select my choices but I can't figure out how to access the choices so I can use the information.
I've tried to run pprint(m_g) but it gives me the error "object is not callable"
if I try to print it with an attribute such as m_g.result it tells me it has no attributes.

def get_m_g(_):
    return [
        "L",
        "G",
        "B",
        "C",
        "S",
        "B",
        "T",
        "Co",
        "Car",
    ]

def main():
    m_g = inquirer.checkbox(
        message="\nChoose the m g:",
        choices=get_m_g,
        validate=lambda result: len(result) > 0 and len(result) <= 2, 
        invalid_message="should be at least 1 m g and no more then 2",
        instruction="(\nselect up to 2 m g)",
    ).execute()
2. can someone explain what is going on here.
if __name__ == "__main__":
      main()
Please use bbtags to hold formatting when posting code.
What is inquirer?
(Dec-26-2023, 09:04 PM)menator01 Wrote: [ -> ]Please use bbtags to hold formatting when posting code.
What is inquirer?

Sorry for not using the bbtags been so long I had forgotten the protocols.
Is there a specific way that we post links as well?

Here is the documentation.
https://python-inquirer.readthedocs.io/en/latest/
(Dec-26-2023, 08:31 PM)cspower Wrote: [ -> ]I've tried to run pprint(m_g) but it gives me the error "object is not callable"
if I try to print it with an attribute such as m_g.result it tells me it has no attributes.
These are not usable error messages. Normally Python prints a long error message called an exception traceback. This long error message gives a lot of information about the issue. Please post Python's complete error messages.
(Dec-26-2023, 09:19 PM)Gribouillis Wrote: [ -> ]
(Dec-26-2023, 08:31 PM)cspower Wrote: [ -> ]I've tried to run pprint(m_g) but it gives me the error "object is not callable"
if I try to print it with an attribute such as m_g.result it tells me it has no attributes.
These are not usable error messages. Normally Python prints a long error message called an exception traceback. This long error message gives a lot of information about the issue. Please post Python's complete error messages.

This is the complete error.
Error:
Traceback (most recent call last): File "/home/cspower/python_projects/D_E_R.py", line 37, in <module> main() File "/home/cspower/python_projects/D_E_R.py", line 29, in main pprint(m_g) TypeError: 'module' object is not callable
(Dec-26-2023, 09:24 PM)cspower Wrote: [ -> ]Error:Traceback (most recent call last): File "/home/cspower/python_projects/D_E_R.py", line 37, in <module>
main()
File "/home/cspower/python_projects/D_E_R.py", line 29, in main
pprint(m_g)
TypeError: 'module' object is not callable
It means that you tried to use the pprint module instead of the pprint function. You can do
pprint.pprint(m_g)
Or alternately you could replace
import pprint
by
from pprint import pprint
(Dec-26-2023, 09:27 PM)Gribouillis Wrote: [ -> ]
(Dec-26-2023, 09:24 PM)cspower Wrote: [ -> ]Error:Traceback (most recent call last): File "/home/cspower/python_projects/D_E_R.py", line 37, in <module>
main()
File "/home/cspower/python_projects/D_E_R.py", line 29, in main
pprint(m_g)
TypeError: 'module' object is not callable
It means that you tried to use the pprint module instead of the pprint function. You can do
pprint.pprint(m_g)
Or alternately you could replace
import pprint
by
from pprint import pprint

It works now thank you