0

I am new to python and I am trying to code a ticket system. I want to be able to print all the tickets that was created. I did append my list. However, when I try to print it it does display the ticket information. I was told that i need to transverse Object_List but i am not sure how to do it. My code is below:


#main.py
from ticket import Ticket
Object_List=[]  #Here you will create list that will keep track of a ll objects in main class
class MenuList(object):
    def menu():
        menu_options = {
            0: 'Exit',
            1: 'Submit help desk ticket' ,
            2: 'Show all tickets',
            3: 'Search ticket by ticket number',
            4: 'Re-open resolved ticket',
            5: 'Display ticket stats'
        }
        print(menu_options)
        option = int(input('Enter your choice: '))
        return option # this function will return choice value selected by user

def submit():
    staffname = input('Enter staff name: ')
    staffid = input('Enter staff ID: ')
    staffemail = input('Enter email address: ')
    issue = input('Description of issue: ')
    if issue == 'Password change':
        newpass = staffid[0:2] + staffname[0:3]
        print("Your new password is: " + newpass)
    ticketobject = Ticket(staffid, staffname, staffemail, issue)
    Object_List.append(ticketobject)
    # here append ticketobj in the Object_List so that each object will keep adding in the list

    Newticket = input('Do you have another problem to submit? (Y/N)')
    if Newticket == 'Y':
        return submit()
    else:
        return selection()

#define stat(object_List method here and travserse through the list and find stats similarly you can define other methods re-opnen, close etc.
def stats():
      for i in Object_List:
          print(i)





def selection():
    op=MenuList.menu()
    if op==0:
        print('Thanks for your submit')
        #enter code here...
    if op == 1:
        submit()
    elif op == 2:
        stats ()
    else:
        print('Incorrect input. Please select from the list: ')
        selection()
#menu will show on your output screen due to this method.....
selection()


#ticket.py
class Ticket():

    datal = [] # this is created in Ticket class
    def __init__(self, staffid, staffname, staffemail, issue):
         ticketnum = 2000
         self.staffid = staffid
         self.staffname = staffname
         self.staffemail = staffemail
         self.issue = issue
         self.status = 'open'
         self.answer = 'None'
         ticketlist = ("staff ID: " + staffid,
                      "staff name: " + staffname,
                      "staff email: " + staffemail,
                      "Description of issue: " + issue,
                      "Ticket status: " + self.status, "Ticket number: ", ticketnum, "Responds: " + self.answer )

         print(ticketlist)
FlyGirll
  • 11
  • 1
  • Does this answer your question? [How to print instances of a class using print()?](https://stackoverflow.com/questions/1535327/how-to-print-instances-of-a-class-using-print) – ILS Nov 17 '22 at 03:18

1 Answers1

0

You need to print each piece of data from the ticket object, trying to print it directly only prints the memory address location.

def stats():
      for i in Object_List:
          print(i.staffid)
          print(i.staffname)
          # and so on, or you can put it in one large print statement and nicely formatted
Trooper Z
  • 1,617
  • 14
  • 31