You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a program that collects some statistics from a dataset. It has two outputs:
A human readable preview printed to the terminal. I wish all float to be printed with precision 4. i.e. 3.141592653 -> 3.1416
A json save file for downstream applications. The numbers should be in their original value.
Currently I am generating a "preview" version of the result with rounded floats just for pretty print, along side a "high-precision" version for json storage.
I wonder is it possible that we control the precision of floats with a parameter?
Example:
data= {
"player": "John",
"games_played": 255,
"win_rate": 166/255, # should be 0.65098039215
}
orignal=json.dumps(data) # output with full precisionrich.pprint(data) # pretty print with full precisionrich.pprint(data, presicion=2) # pretty print with precision = 2
Adding a parameter that is specific to ints (or any parameter honestly) in the pprint function seems rather difficult.
Perhaps you can go in the route of enquiring a specific console object, IMO adding a precision parameter to the console constructor isn't that bad, but could also use a custom formatter or what not.
I have a program that collects some statistics from a dataset. It has two outputs:
3.141592653
->3.1416
json
save file for downstream applications. The numbers should be in their original value.Currently I am generating a "preview" version of the result with rounded floats just for pretty print, along side a "high-precision" version for json storage.
I wonder is it possible that we control the precision of floats with a parameter?
Example:
Should print:
The text was updated successfully, but these errors were encountered: