Jump to content

need help with some debugging of a python script


Recommended Posts


hello dear experts,


need help with some debugging of a python script

well this is python 3 based - but i have issues to get it up and running

i use eric 6

	 
	#!/usr/bin/env python3
"""
contacts.py
This program uses a Person class to keep track of contacts.
"""
	class Person(object):
    """
    The Person class defines a person in terms of a
    name, phone number, and email address.
    """
    # Constructor
    def __init__(self, theName, thePhone, theEmail):
        self.name = theName
        self.phone = thePhone
        self.email = theEmail
    # Accesser Methods (getters)
    def getName(self):
        return self.name
    def getPhone(self):
        return self.phone
    def getEmail(self):
        return self.email
    # Mutator Methods (setters)
    def setPhone(self, newPhoneNumber):
        self.phone = newPhoneNumber
    def setEmail(self, newEmailAddress):
        self.email = newEmailAddress
    def __str__(self):
        return "Person[name=" + self.name + \
               ",phone=" + self.phone + \
               ",email=" + self.email + \
               "]"
	def enter_a_friend():
    name = input("Enter friend's name: ")
    phone = input("Enter phone number: ")
    email = input("Enter email address: ")
    return Person(name, phone, email)
	def lookup_a_friend(friends):
    found = False
    name = input("Enter name to lookup: ")
    for friend in friends:
        if name in friend.getName():
            print(friend)
            found = True
    if not found:
        print("No friends match that term")
	def show_all_friends(friends):
    print("Showing all contacts:")
    for friend in friends:
        print(friend)
	def main():
    friends = []
    running = True
    while running:
        print("\nContacts Manager")
        print("1) new contact    2) lookup")
        print("3) show all       4) end ")
        option = input("> ")
        if option == "1":
            friends.append(enter_a_friend())
        elif option == "2":
            lookup_a_friend(friends)
        elif option == "3":
            show_all_friends(friends)
        elif option == "4":
            running = False
        else:
            print("Unrecognized input. Please try again.")
    print("Program ending.")
	if __name__ == "__main__":
    main()
	    
	

any ideas what i have done wrong

 

need help with some debugging of a python script well this is python 3 based - but i have issues to get it up and running

i use eric 6 and the eric opened the code automatically but eric is not configured at all.

how to get ahead..!?

hello see my approach

if i do like so - in eric

1
    Python 3.7.1 (default, Oct 22 2018, 10:41:28)
2
    [GCC 8.2.1 20180831] auf martin-pc, Standard
3
    >>> contacts.py
4
    >>> Traceback (innermost last):
5
      File "<stdin>", line 1, in <module>
6
    NameError: name 'contacts' is not defined

i get errors...

what goes wrong here -

i guess that the Python interpreter understands and accepts only Python commands.
i tried to run contacts.py in the interpreter, which is not a Python command.

To run the code of the contacts.py file in Eric, simply open it and select Start > Run Script from the Eric main menu

From Python documentation:
https://docs.python....error#NameError

exception NameError
Raised when a local or global name is not found. This applies only to unqualified names. The associated value is an error message that includes the name that could not be found.


i runned it like so - AND now it woks propperly

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.