i am trying to create a contact list in python. And i am trying to save entered inputs to a txt. and when user wanted to look for a contact from list, i want from program is read the txt file and answer to the user. Thanks
with little research on internet i have found :
with open('list','w') as f:
f.write()
this technic. But i am new to python thanks for help.
import optparse
def contact_add():
contact_list = optparse.OptionParser()
contact_list.add_option("-n","--name",dest="name",help="name to enter")
contact_list.add_option("-t","--telephone",dest="telephone",help="tel no to enter")
with open('list','w') as f:
return f.write(contact_list.name,contact_list.telephone)
The command line :
python contact.py -n hanter -t 0555
This is the output when launched:
Traceback (most recent call last):
File "contact.py", line 13, in <module>
contact_add()
File "contact.py", line 11, in contact_add
return f.write(contact_list.name,contact_list.telephone)
AttributeError: 'OptionParser' object has no attribute 'name'