Situation: you have a floating point number with a number of digits after the decimal point and you want to round to 2 decimal places.
result = 4.2700000000000005
roundedResult = str(round(result, 2))
print(f"The rounded number is: {roundedResult}")
Output:
The rounded number is: 4.27
import json
filename = "file.json"
with open(filename, 'r') as file:
fileContents = file.read()
jsonData = json.loads(fileContent)
Now 'jsonData' is loaded as a Python dictionary and can be accessed as a dictionary
import json
nastyJson = "jsonData.json"
with open(nastyJson, 'r') as file:
dataRead = json.loads(file.read())
print(json.dumps(dataRead, indent=4))
import lxml.etree as etree
inFile = "source.xml"
outFile = "output.xml"
x = etree.parse(inFile)
newContent=etree.tostring(x, pretty_print=True)
with open(outFile, 'w') as outxml:
outxml.write(str(newContent))
print("done")