I went thru all questions raised in this topic but my case seems to be slightly different.
In different file from class below I’m importing get_pressure
function. Because it’s related to main
I get error:
TypeError: PressureGauge.get_pressure() missing 1 required positional argument: 'self'
Class I’m importing from:
class PressureGauge:
def __init__(
self,
measurementRange = ( None, None ),
hasDegas = False,
deviceSupportedUnits = [ PressureGaugeUnit.MBAR ],
debug = False
):
if not isinstance(measurementRange, tuple) and not isinstance(measurementRange, list):
raise ValueError("Measurement range has to be tuple or list with two components")
if len(measurementRange) != 2:
raise ValueError("Measurement range can only have two component")
if measurementRange[0] > measurementRange[1]:
raise ValueError("Measurement range minimum is larger than maximum")
if len(deviceSupportedUnits) < 1:
raise ValueError("Measurement units of device are unknown")
self._debug = debug
self._usesContext = False
self._usedConnect = False
self._supportedUnits = deviceSupportedUnits
self._hasDegas = hasDegas
def get_pressure(self, unit = PressureGaugeUnit.MBAR):
if not isinstance(unit, PressureGaugeUnit):
raise ValueError("Unit has to be one the supported pressuage gauge units")
resp = self._get_pressure()
if resp is None:
return None
if unit in resp['value']:
return resp['value'][unit]
# Check if we can perform the conversion from MBAR to the given unit
if unit == PressureGaugeUnit.MBAR:
return resp['mbar']
elif unit == PressureGaugeUnit.TORR:
return resp['mbar'] * 0.750062
elif unit == PressureGaugeUnit.PASCAL:
return resp['mbar'] * 100.0
else:
raise ValueError(f"Unknown unit {unit}")
How I should “wrap” whole class to avoid error?