Quantcast
Channel: Give a number units when used through a class - Stack Overflow
Browsing latest articles
Browse All 5 View Live

Answer by Paul92 for Give a number units when used through a class

There are ways of doing it, but firstly you should ask yourself whether you want this. Having different units can get confusing. You can put conversions at the appropriate places (e.g. after reading...

View Article


Answer by N Chauhan for Give a number units when used through a class

To override the string representation of the number, make a wrapper class:class FloatWrapper: def __init__(self, float, unit): self.float = float self.unit = unit def __getattr__(self, key): try:...

View Article


Answer by Gagan for Give a number units when used through a class

This works?Basically I have added another property to the Atom class so that all objects of type Atom can use it. Another way of doing it would be to pass it as you are doing with the...

View Article

Answer by hallie for Give a number units when used through a class

I'm not sure if this is exactly what you're looking for, but you could have a method inside the Atom class that prints the mass of the atom plus a unit string.class Atom: def __init__(self, protons,...

View Article

Give a number units when used through a class

I'm trying to get a class to spit out a number with units. The purpose of it having units would be to be able to work with the number later, but without the units getting in the way as a string. Though...

View Article

Browsing latest articles
Browse All 5 View Live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>