kdavies4 / natu

Natural units in Python
http://kdavies4.github.io/natu/
Other
33 stars 5 forks source link

Question: convert all quantities to plain floats? #33

Open zbeekman opened 7 years ago

zbeekman commented 7 years ago

I'm trying to output a dictionary containing natu quantities as a JSON file. I'm having trouble because I can't directly call json.dumps(dict,fp) because json doesn't know how to serialize quantity objects.

Is there an easy way to convert all quantities to floats?

SweRavn commented 6 years ago

Yes, see here: http://nbviewer.jupyter.org/github/kdavies4/natu/blob/master/examples/tutorial.ipynb#Disabling-quantities

zbeekman commented 6 years ago

I don't think this is a viable solution for me because I have to set this before the module is imported. I.e., disabling quantities will disable them globally, but I want to be able to output a dictionary containing natu quantities as floats. Unless I'm missing something your suggestion will globally disable natu.