The following code needs to get the value of the element, but the output is empty

[reflection.assembly]::LoadFrom("C:\Program Files\IronPython 2.7\IronPython.dll")
$py = []::CreateEngine()
$pyv = $py.CreateScope()
$pyc = $py.CreateScriptSourceFromString("d = {'one':1,'two':2}")
$d = $pyv.GetVariable("d")

1 Answers

Abhijith pk On Best Solutions

You can use the get("key") function or $variable["key"] to get dictionary values :

$engine = []::CreateEngine()
$pyv = $engine.CreateScope()
$pyc = $engine.CreateScriptSourceFromString("d = {'one':1,'two':2}")
$d = $pyv.GetVariable("d")

This is the expected behavior with python dictionaries,if you try get-member on the object then you can see that the properties one and two are not there but powershell won't throw error even if you try to access properties that are not there