Use of the Python API in Matlab and Converting Python Results to Matlab Objects

LabKey Support Forum (Inactive)
Use of the Python API in Matlab and Converting Python Results to Matlab Objects cmwest3  2017-10-26 10:38
Status: Closed
 
I was looking for the code responsible for placing an underscore in front of python dictionary keys and was thinking that might be it. But, I have found a way to rename the key within Matlab so that it conforms to struct naming conventions:

try
    matObj = struct(pyObj);
catch ME
    if strcmp(ME.identifier, 'MATLAB:Cell2Struct:InvalidFieldName')
        offending_key = regexp(ME.message, '(?<=")[^"]+(?=")', 'match');
        offending_key = offending_key{1};
        pyObj{offending_key(2:end)} = pyObj.pop(offending_key);
        matObj = struct(pyObj);
    end
end