Skip to main content

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


Download files

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

Source Distribution

tempera-1.0.1.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tempera-1.0.1-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file tempera-1.0.1.tar.gz.

File metadata

  • Download URL: tempera-1.0.1.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.23.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.52.0 CPython/3.7.4

File hashes

Hashes for tempera-1.0.1.tar.gz
Algorithm Hash digest
SHA256 9d6b3c52c3ae051e2fe09499b701420bf89dda5c81fa91b70ec355a256c1e924
MD5 ccff5fff1ba1094c84a0efad94d04693
BLAKE2b-256 72b49f52c488bd66c4d600a048846917510b3458a76fd5ae7c79ac1b16fe5d28

See more details on using hashes here.

File details

Details for the file tempera-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: tempera-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.23.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.52.0 CPython/3.7.4

File hashes

Hashes for tempera-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 627a5f140734d13411174b72f458c6aebf4c9b8822088cfd7e8926239c67e556
MD5 cc6674f9741b660af6ff63b8f56850e3
BLAKE2b-256 bf129548c423e989e9a05f776b0449efdec139d7450342d20067bceb3f49b14d

See more details on using hashes here.

Supported by

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