doug-101 / ConvertAll-py

a flexible unit converter
http://convertall.bellz.org
39 stars 15 forks source link

Suggestion: Use CovertAll in Python Programming #20

Closed kookma closed 1 year ago

kookma commented 3 years ago

We (I and any of my students) are a daily users of this amazing app! I have never seen before any tool for unit conversion like CovertAll.

One suggestion: Is it possible to release a library or a package to use CovertAll in our Python scripts directly!

Something like

import convertall as cu

x= 2 #Pa
z = 3.75 #m/s
y = x * cu.convert(Pa, atm)
w = z * cu.convert(m/s, ft/hr)
doug-101 commented 3 years ago

I don't have any plans to do so, but it shouldn't be too difficult to call the existing ConvertAll code from scripts. The core conversions are done in the following source files: unitatom.py, unitdata.py and unitgroup.py. The code in those files can run completely independently of the GUI code.

It would also be helpful to look at cmdline.py, which provides a command-line interface for conversions. It is probably more than you need, since it also reads option files and can provide prompts. But it may make it easier to see how to use the files mentioned above in a script.

-Doug

kookma commented 3 years ago

Thank you very much @doug-101. I go through and update you here!

J-Saeedi commented 1 year ago

Thank you very much @doug-101. I go through and update you here!

Did you make any progress in creating ConvertAll's python library?

doug-101 commented 1 year ago

I don't have any plans to change that. See my reply above about how it could either be used directly in a script or be adapted.