::-- limodou [DateTime(2005-09-14T06:31:19Z)] TableOfContents
1. Dict4Ini
This module is used to process ini format configuration file. It acts just like a dict, but you can also access it's sections and options with attribute syntax, just like x.test.
1.1. Why reinvent this module?
I used Config4Obj module for GoogleTalkBot software (confbot) to deal with configuration file. But I found its lacks on:
- Only can access options as x['name']['o'], but not as x.name.o
- You must create section first, so you can access its options. So if you didn't create x['name']={} section, so you cann't do x['name']['o'] = 3
The option's data can be saved as string format, but as read out again, Config4Obj cann't convert it to their original value type, so you must conver it yourself
- Didn't support unicode
*Above is my opinion, so may be not right. *
So I decide to _reinvent_ a new module to solve there lacks, I named it as Dict4Ini, it means you can see the object is just like a dict.
1.2. What's it features
- as simple as others
- you can access options according to dict syntax, just like x['name']['o'] = 1, x['name'].keys(), x['name'].values(), etc.
- you also can access options according to attr syntax, just like x.name.o = 1, x.name.keys(), x.name.values, etc. So the name must be Identifier or single word.
- you can save comments in it(but this feature is not tested so much)
- support multi level section, subsection name will just like: [firsub/secsub]
- It's a litter module, just for my mind, so if you like, you should try it, but if you don't like, just skip it, that's ok
1.3. Examples
1.3.1. Examples 1 Create a ini file
This example will save option to test.ini. As you can see, you needn't create section "common" at first, just think it's there, it's ok. The result of test.ini is:
{{{[common] list = 3,Hello,"have spaces", bool = 1 name = limodou}}}
And you can see, once the value has special chars, just like ' ', ',', '\"', etc, the string will be quoted by double quoter. But "Hello" is a single word, and it has not the special chars, so it won't be quoted. If the value is number, it'll be just like number literal, but if the value is number string, it'll be quoted by double quoter.
In this time, the Dict4Ini support number, list, string, unicode data type, for others you should convert yourself.
1.3.2. Example 2 Open an existed ini file
So it's easy. The result will be: