In my program, I have an input function which adds a string to a list with multiple other values. Is there a way to keep the input in the list as an item after the program has ended?
For example:
list = ['a', 'b', 'c']
addToList = input('Type string to add to list: ')
list.append(addToList)
If I added the string 'd' through the variable 'addToList', how could I make it so the 'd' would be an item in the list next time I ran the program
Would look like this:
list = ['a', 'b', 'c', 'd']
addToList = input('Type string to add to list: ')
list.append(addToList)
list, uselist_orli. It's better to snuff out these habits sooner than later.import ConfigParser config = ConfigParser.ConfigParser() config.read('example.cfg') print list(config.get('Section 1', 'list').split(' '))Content ofexample.cfgis: ` [Section 1] list =a b c` To set a value use:config.set('Section 1', 'list', 'a b c d') with open('example.cfg', 'wb') as configfile: config.write(configfile)