In this post I going to use a Python dictionary to store my configuration variables:
"""
Configuration of my application
"""
Configuration = {
"Server" : "TOTO",
"Database" : "Rene",
"Debug" : True,
"MaxUser" : 3,
"Users" : ["rdescartes", "bpascal", "cmontesquieu"]
}
How to read this configuration variables in C# 4.0.
static void Demo() {
ScriptRuntime PythonScriptRuntime = Python .CreateRuntime();
dynamic PythonScript = PythonScriptRuntime.UseFile("Configuration2.py" );
Console.WriteLine(PythonScript.Configuration["Server" ]);
Console.WriteLine(PythonScript.Configuration["Database" ]);
Console.WriteLine(PythonScript.Configuration["Debug" ]);
Console.WriteLine(PythonScript.Configuration["MaxUser" ]);
foreach (string u in PythonScript.Configuration["Users" ]){
Console .WriteLine(u);
}
Console .ReadLine();
}
No comments:
Post a Comment