A simple library for temperature unit conversion
Project description
ctof
A simple library for temperature unit conversion
PyPI Library
ctof is a library for inter-conversion of Celsius, Fahrenheit and Kelvin values. ctof works with ints and floats, as well as lists, tuples and sets, allowing for multiple values to be converted at once.
Installation
pip install ctof
Import with: import ctof
Functions
There are only a couple of functions in ctof 0.2.0:
ctof.convert(values, _from, _to)
This function is the entire ctof library's core functionality.
values
can be an int, float or a list/tuple/set of ints/floats.
_from
and _to
indicate the temperature to convert from and the
temperature to convert to, respectively. They can be "C", "F" or "K".
ctof.version()
Prints out the current version and release date.
Tests
pytest tests/test-ctof.py
Examples
Convert an integer
import ctof
print(ctof.convert(32, "F", "C")) # Value is in Fahrenheit
# Output: 0.0
print(ctof.convert(0, "C", "F")) # Value is in Celsius
# Output: 32.0
Convert a float
print(ctof.convert(111.11, "F", "C"))
# Output: 43.95
Convert from a variable
var1 = 86
var2 = 38
print(ctof.convert(var1, "F", "C"))
# Output: 30.0
print(ctof.convert(var2, "C", "F"))
# Output: 100.4
Convert from list, tuple and set
mylist = [37, 38, 39]
mytuple = (86, 87, 88)
myset = {273.15, 373.15}
print(ctof.convert(mytuple, "F", "C"))
# Output: (30.0, 30.555555555555557, 31.11111111111111)
print(ctof.convert(mylist, "C", "F"))
# Output: [98.6, 100.4, 102.2]
print(ctof.convert(myset, "K", "C"))
# Output: {0.0, 100.0}
Formatted (rounded) output
print(round(ctof.convert(86.9125, "F", "C"), 3)) # Round method
print("{:.3f}".format(ctof.cel(86.9125))) # Format method
print(ctof.cel(86.9125)) # Raw output
# Both methods return 30.507
# (30.506944444444443 without formatting)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file ctof-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: ctof-0.2.1-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e28aed61b8f5ca5c3adc64ddeeeb9000639a39978a1e5040d26097f7a89ce4c |
|
MD5 | 452a0993e010a405c48d73df10c28fb2 |
|
BLAKE2b-256 | a3e7edbef39e3af95723522d32add3591ab4bfa236246cf5521cc8ca1496d0f2 |