Ems
Ems

Reputation: 15

Saving name, number and alias from a dynamic phonebook to a file

I'm making a dynamic phone-book where you can save name, number and alias. When you are done you can choose too save everything to a file, this is where the problem comes. I've figured out how to save my names and numbers, but not the aliases.

this is a piece of the function where i save my alias:

def main()
..stuff
    def alias(person_list, input_list):
        ..stuff..
        for persons in list(person_list):
             ..stuff..
             person_list[person_list.index(persons)].addAlias(newname)
             print "Alias saved"

the methods i use:

class person():
   ..stuff..
   def addAlias(self, alias):
        self.alias.append(alias)

    def hasAlias(self, alias):
        if alias in self.alias:
            return True
        else:
            return False

this is the function where i want to save everything:

def save(input_list, person_list):
    filename = input_list[1]
    f = open(filename, "w")
    for i in range(0, len(person_list)):
        line = person_list[i].number + ";" + person_list[i].name + ";" + "\n"
        f.write(line,) 
    f.close

I can find out if the element person_list[i] has an alias with the method hasAlias, but I can't figure out how I can get out the value alias, not just True and False, and print that together with the name and number.

Upvotes: 0

Views: 244

Answers (1)

Prune
Prune

Reputation: 77880

Your problem description isn't quite clear enough for me to be sure what you want. Please refer to MCVE.

I think that you're merely missing a method to retrieve the alias, such as

getAlais(self):
    return self.alias

Then you simply include that call in your output line. If this isn't what you mean by "get out the value alias", then please clarify.

Upvotes: 0

Related Questions