Python Forum
Grabing email from a class with input from name
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Grabing email from a class with input from name
#1
I'm wondering if there is a way where I can grab where I can grab an email from a class with in put from a name I know I can do this from making a list with the contact from the class but I have been driving myself crazy because I'm basically making a contact list twice and I feel like there definite has to be a better way 

so basically from the code I will import as an example I want to have an input like input("send to: ") and I type in John Doe and get his email from the Contact class so I can use it for smtplib
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, self.last_name, ", Email:", self.email)

john = Contacts("john", "Doe", "[email protected]")
Reply
#2
this is what I'm using right now to retrieve the email but I'm making a list instead of grabbing directly from the class I want to eliminate this step if possible 
 
def contact_list():
    x = input("send to: ")
    contact_list_names = ["john",]
    contact_list_info = [Contacts.john.email,]
    return contact_list_info[contact_list_names.index(x)]
Reply
#3
Anyone?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  class Update input (Gpio pin raspberry pi) caslor 2 742 Jan-30-2023, 08:05 PM
Last Post: caslor
  Using input function in a Class wew044 2 2,236 Feb-06-2020, 03:08 AM
Last Post: wew044
  user input to select and print data from another class python TyTheChosenOne 6 4,056 Aug-30-2018, 05:53 PM
Last Post: TyTheChosenOne
  [Help] Using "Class" with User Input in an online sign up form vanicci 8 6,553 Aug-29-2018, 10:52 AM
Last Post: vanicci
  An email with inline jpg cannot be read by all email clients fpiraneo 4 3,931 Feb-25-2018, 07:17 PM
Last Post: fpiraneo
  Email - Send email using Windows Live Mail cyberzen 2 5,871 Apr-13-2017, 03:14 AM
Last Post: cyberzen

Forum Jump:

User Panel Messages

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