can ConfigParser deal with repeating section header?

2015-11-12 Thread John Zhao
I have a configuration file with repeating sections, for example, 

[INSTANCE]
Name=a

[INSTANCE]
Name=b


I hope I can use ConfigParser to read the file and store the configuration 
settings in arrays.  

Is that possible?

Thanks a lot.

John
-- 
https://mail.python.org/mailman/listinfo/python-list


Persist objects in a LIST

2015-11-14 Thread John Zhao
I am new to Python, and just learned that Python list is just a container of 
object reference.   

In the example below,  bDict needs to be just a temporary object, constructed 
at run time and then be added to aList.   At the end, aList will contain n 
objects.

Is there a clean way to do that?

Many thanks, 

John

$ ipython
WARNING: IPython History requires SQLite, your history will not be saved
WARNING: Readline services not available or not loaded.
WARNING: The auto-indent feature requires the readline library
Python 2.7.9 (default, Sep  5 2015, 07:20:36)
Type "copyright", "credits" or "license" for more information.

IPython 4.0.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help  -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.
In [1]: aList = []
In [2]: bDict = {}
In [3]: bDict['instance_name']='SERVER_TIER'
In [4]: aList.append(bDict)
In [5]: print aList
[{'instance_name': 'SERVER_TIER'}]
In [6]: bDict.clear()
In [7]: print aList
[{}]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Persist objects in a LIST

2015-11-14 Thread John Zhao
I found a solution.  replace  bDict.clear() with  bDict = {} 

thanks,

John
-- 
https://mail.python.org/mailman/listinfo/python-list