Python Forum
How to access values returned from inquirer
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to access values returned from inquirer
#1
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()
Reply
#2
Please use bbtags to hold formatting when posting code.
What is inquirer?
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#3
(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/
Reply
#4
(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.
« We can solve any problem by introducing an extra level of indirection »
Reply
#5
(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
Reply
#6
(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
« We can solve any problem by introducing an extra level of indirection »
Reply
#7
(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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  dict class override: how access parent values? Andrey 1 1,644 Mar-06-2022, 10:49 PM
Last Post: deanhystad
  SQLAlchemy Object Missing when Null is returned Personne 1 1,752 Feb-19-2022, 02:50 AM
Last Post: Larz60+
  Getting "name 'get_weather' is not defined error and no json_data returned? trthskr4 6 3,655 Sep-14-2021, 09:55 AM
Last Post: trthskr4
  Libraries installed with pipenv, but ModuleNotFoundError returned jpncsu 2 3,018 Sep-06-2021, 07:24 PM
Last Post: jpncsu
  access dictionary with keys from another and write values to list redminote4dd 6 3,270 Jun-03-2020, 05:20 PM
Last Post: DeaD_EyE
  Exception: Returned Type Mismatch Error devansing 1 5,172 Mar-06-2020, 07:26 PM
Last Post: ndc85430
  How to access specific values from a dict? t4keheart 6 3,118 Feb-05-2020, 11:34 PM
Last Post: metulburr
  How to use a returned value? t4keheart 12 4,885 Jan-16-2020, 06:54 AM
Last Post: perfringo
  Strange Characters in JSON returned string fioranosnake 4 5,233 Dec-02-2019, 07:25 PM
Last Post: fioranosnake
  Not all data returned from sys.argv ecdhyne 2 2,774 Sep-05-2019, 08:27 PM
Last Post: buran

Forum Jump:

User Panel Messages

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