I have been using the DictParser created as mentioned in previous blog in a recent project to create a setting file for various users. In the project, different users need to have different settings such as parameter filepath.
The setting file created will use the computer name to segregate the different users. By creating a text file (with Dict Parser) based on the different computer names, it is easy to get separate setting parameters for different users. Sample of the setting file are as below.
## Text file $USER1_COM_NAME #setting_comment_out:r'c:\data\temp\bbb.txt' setting2:r'c:\data\temp\ccc.txt' $USER2_COM_NAME setting:r'c:\data\temp\eee.txt' 2:1,bbb,cccc,1,2,3 ## end of file
The output from DictParser are as followed:
## python output as one dict containing two dicts with different user'USER1_COM_NAME' and 'USER2_COM_NAME' >> {'USER1_COM_NAME': {'setting2': ['c:\\data\\temp\\ccc.txt']}, 'USER2_COM_NAME': {2: [1, 'bbb', 'cccc', 1, 2, 3], 'setting': ['c:\\data\\temp\\eee.txt']}}
User can use the command “os.environ[‘ComputerName’]” to get the corresponding setting filepath.
I realized that the output format is somewhat similar to json format. This parser is more restrictive in uses hence has some advantage over json in less punctuations (‘{‘, ‘\’) etc and able to comment out certain lines.
One comment