Skip to main content

A simple library for temperature unit conversion

Project description

ctof

A simple library for temperature unit conversion

PyPI Library

PkgVersion PythonVersion PythonImplementation License Wheel


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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

ctof-0.2.1-py3-none-any.whl (4.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page