Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
adding user to a class
#1
once a class is made how to I add contacts to it in the future with input as apposed to manually inputting the code for example lets say I wanted to add john doe with inputs from a user and store it instead of doing it manually also I want to be able to store a couple so setting john to a variable and grabbing data from that list wouldn't work, also is there a way to keep that stored data if I need to rerun the program I have seen code for address books however the data thats stored in a list is lost once the program is re ran 
 
class Contacts:
    contactCont= 0
    def __init__(self, first_name,last_name, email):
        self.first_name = first_name
        self.last_name = last_name
        self.email = email

        Contacts.contactCont +=1
    def display_contact(self):
        print("First Name : ", self.first_name,", Last Name: ",self.last_name, ", Email: ", self.email)

    def name(self):
        n = self.first_name, self.last_name
        return n

    def email(self):
        e = self.email
        return e


john = Contacts("john", "Doe", "[email protected]")
Reply


Messages In This Thread
adding user to a class - by Nickd12 - Oct-14-2020, 09:05 PM
RE: adding user to a class - by sblancov - Oct-14-2020, 09:35 PM
RE: adding user to a class - by Skaperen - Oct-14-2020, 09:51 PM
RE: adding user to a class - by deanhystad - Oct-15-2020, 03:55 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Adding markers to Folium map only adding last element. tantony 0 2,283 Oct-16-2019, 03:28 PM
Last Post: tantony
  user input to select and print data from another class python TyTheChosenOne 6 4,393 Aug-30-2018, 05:53 PM
Last Post: TyTheChosenOne
  [Help] Using "Class" with User Input in an online sign up form vanicci 8 6,937 Aug-29-2018, 10:52 AM
Last Post: vanicci
  Adding C methods to a pure python class relent95 1 3,017 Nov-03-2017, 03:24 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

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