Convert and return temperature objects in set global scale.
Project description
Tempera
Description
Create temperature objects which return their value in a set 'global' unit scale - either Celsius, Fahrenheit, or Kelvin - using the method getTemperature(). When the Global temperature scale is changed, all temperature objects are returned in that scale.
I created this module to easily convert multiple temperatures displayed on a GUI when a user selects a different scale. I imagine it could be useful any time one has multiple persistant temperatures that need to undergo unit conversion at will.
Using this Module
The Global temperature scale can be set with the method self.setGlobalScale(). All Temperature objects will return in this scale with self.getTemperature().
Set or return from a specific scale using self.c for Celsius, self.f for Fahrenheit, and self.k for Kelvin.
Local Scales
If you want a specific Temperature object to return self.getTemperature() in a different scale regardless of the current global scale, use self.setLocalScale(). Can return to using global scale with self.setLocalScale(False) or self.useGlobalScale().
Rounding
Set the number of decimal places with the decimal_place keyword argument:
from tempera import Temperature
temp1 = Temperature(12, decimal_place=2)
Or with self.setDecimalPlace(int), where int is an integer. The default decimal place is 2. Setting to None will always return a rounded integer.
Intervals
Temperature objects can also represent intervals instead of actual temperatures with the keyword argument isinterval=True. For example, if you wanted to represent an interval of 3 celsius units:
temp_interval = Temperature(3, isinterval=True)
print(temp1.C + temp_interval.C) # Adds 3 celsius to temp1 and prints
How it functions
The temperature is stored internally in Celsius. All setting and getting of the temperature in different scales is a conversion from this 'private' celsius attribute. This attribute is not rounded. Any rounding is done when getTemperature() (or a similar method) is called, so setting a decimal place does not affect the internally stored temperature.
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.