![]() |
| ||
| Adress book Hi attempting to make an address book program but hit a snag- I have: A class to give various attributes(phone numbers etc)to an instance which then puts it all into a doc string which can be added to a dictionary- but I want a function that will ask the user for the relevant information and then feed it to the class as the relevant arguments. however I Can't figure that out. Any Ideas-Section of code below: class Data:Please help!!!!!! |
| ||
| Re: Adress book Oh I see, you want the instance name be the name of the person. That will not be a good idea, because identifiers in Python don't allow spaces. A dictionary, where the name is the key and the value is a ( home, mobile, email ) tuple or list will do much better. You could also make the class instance the value of your dictionary. |
| ||
| Re: Adress book Thanks, but making the class instance the value of the dictionary does not work it just returns the location of the instance in hexadecimal notation. I have rejigged the code: class Data:I intend to add it to the dictionary using self.info as the value. But I really need a function that will create a variable and asign it to class Data. |
| ||
| Re: Adress book This works just fine: # create a dictionary of class instance valuesRemember that the name string is the dictionary key and has to be unique. |
| ||
| Re: Adress book Thanks that was extremely helpful |
| ||
| Re: Adress book Using the code you gave me, I modified it a bit to enable more easy user interaction, but I want a function to change an attribute of an entry, say the email. heres the code so far intro = "Welcome to Adress_Book.py"so how can I take n_e and swap it for the old email adress |
| ||
| Re: Adress book sorry my mistake :) intro = "Welcome to Adress_Book.py"I want to write file I/O for this, having tried before and failed, so could someone pls point me in the right direction. |
| ||
| Re: Adress book Let's say you want to change the email: # a test setup |
| ||
| Re: Adress book cheers, but do you have any ideas on pickleing this to create file io especially regarding the load |
| ||
| Re: Adress book I have to say that from python 2.5 and on you can use the 'a' file open method (append), which just adds to the data already in the file, i changed all of my programs to use this instead and it works so much faster |
| All times are GMT -4. The time now is 3:42 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC