Python Forum
user input to select and print data from another class python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
user input to select and print data from another class python
#6
Okay, then how about:

choice = input('Choose an item to view the details of: ').lower()
for item in self.inventory:
    if choice == item.name:
        item.getdetails()
It would be more efficient if you stored it as a dictionary rather than a list. Then you wouldn't need the loop. Also, your use of raw_input makes me think you are using Python 2.x. You should switch to Python 3.x.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
RE: user input to select and print data from another class python - by ichabod801 - Aug-30-2018, 05:03 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to Randomly Print a Quote From a Text File When User Types a Command on Main Menu BillKochman 13 1,150 Apr-24-2024, 05:47 AM
Last Post: Bronjer
  Help with to check an Input list data with a data read from an external source sacharyya 3 506 Mar-09-2024, 12:33 PM
Last Post: Pedroski55
  manually input data jpatierno 0 372 Nov-10-2023, 02:32 AM
Last Post: jpatierno
  Input network device connection info from data file edroche3rd 6 1,160 Oct-12-2023, 02:18 AM
Last Post: edroche3rd
  WHILE LOOP NOT RETURNING USER INPUT AFTER ZerroDivisionError! HELP! ayodele_martins1 7 1,137 Oct-01-2023, 07:36 PM
Last Post: ayodele_martins1
Question in this code, I input Key_word, it can not find although all data was exact Help me! duchien04x4 3 1,118 Aug-31-2023, 05:36 PM
Last Post: deanhystad
  print(data) is suddenly invalid syntax db042190 6 1,273 Jun-14-2023, 02:55 PM
Last Post: deanhystad
  restrict user input to numerical values MCL169 2 983 Apr-08-2023, 05:40 PM
Last Post: MCL169
  class Update input (Gpio pin raspberry pi) caslor 2 858 Jan-30-2023, 08:05 PM
Last Post: caslor
  user input values into list of lists tauros73 3 1,113 Dec-29-2022, 05:54 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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