How to parse linuxcnc.var using Python
with open("/home/cnc/linuxcnc/configs/myCNC/linuxcnc.var") as infile:
lines = infile.readlines()
splitted = [line.strip().partition("\t") for line in lines]
linuxCNCVar = {int(splitResult[0]): float(splitResult[-1]) for splitResult in splitted}
Example output for linuxCNCVar
:
{5161: 0.0,
5162: 0.0,
5163: 0.0,
5164: 0.0,
5165: 0.0,
5166: 0.0,
5167: 0.0,
5168: 0.0,
5169: 0.0,
5181: 0.0,
5182: 0.0,
5183: 0.0,
5184: 0.0,
5185: 0.0,
5186: 0.0,
5187: 0.0,
5188: 0.0,
5189: 0.0,
5210: 0.0,
5211: 0.0,
5212: 0.0,
5213: 0.0,
5214: 0.0,
5215: 0.0,
5216: 0.0,
5217: 0.0,
5218: 0.0,
5219: 0.0,
5220: 1.0,
5221: 7.40119,
5222: 13.549249,
5223: 298.476583,
5224: 0.0,
5225: 0.0,
5226: 0.0,
5227: 0.0,
5228: 0.0,
5229: 0.0,
5230: 0.0,
5241: 36.868548,
5242: 141.752329,
5243: 207.563262,
5244: 0.0,
5245: 0.0,
5246: 0.0,
5247: 0.0,
5248: 0.0,
5249: 0.0,
5250: 0.0,
5261: 36.868548,
5262: 145.029329,
5263: 207.563262,
5264: 0.0,
5265: 0.0,
5266: 0.0,
5267: 0.0,
5268: 0.0,
5269: 0.0,
5270: 0.0,
5281: 36.89201,
5282: 144.834924,
5283: 207.935105,
5284: 0.0,
5285: 0.0,
5286: 0.0,
5287: 0.0,
5288: 0.0,
5289: 0.0,
5290: 0.0,
5301: 0.0,
5302: 0.0,
5303: 0.0,
5304: 0.0,
5305: 0.0,
5306: 0.0,
5307: 0.0,
5308: 0.0,
5309: 0.0,
5310: 0.0,
5321: 0.0,
5322: 0.0,
5323: 0.0,
5324: 0.0,
5325: 0.0,
5326: 0.0,
5327: 0.0,
5328: 0.0,
5329: 0.0,
5330: 0.0,
5341: 0.0,
5342: 0.0,
5343: 0.0,
5344: 0.0,
5345: 0.0,
5346: 0.0,
5347: 0.0,
5348: 0.0,
5349: 0.0,
5350: 0.0,
5361: 0.0,
5362: 0.0,
5363: 0.0,
5364: 0.0,
5365: 0.0,
5366: 0.0,
5367: 0.0,
5368: 0.0,
5369: 0.0,
5370: 0.0,
5381: 0.0,
5382: 0.0,
5383: 0.0,
5384: 0.0,
5385: 0.0,
5386: 0.0,
5387: 0.0,
5388: 0.0,
5389: 0.0,
5390: 0.0}