Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # SimpleSample Class
- class sensor(object):
- def __init__(self, quantity, unit, value=None):
- self.quantity = quantity
- self.value = value
- self.unit = unit
- def store_value(self, value):
- self.value = value
- def __str__(self):
- return "{quantity} has a value of {value} {unit}".format(
- quantity = self.quantity,
- value = self.value,
- unit = self.unit)
- humidity = sensor("Humidity", "%", 65)
- print(humidity) # Output: Humidity has a value of 65 %
- temperature = sensor("Temperature", "'C")
- temperature.store_value(12.2)
- print(temperature) # Temperature has a value of 12.2 'C
- print(temperature.quantity) # Temperature
- print(temperature.value) # 12.2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement