pythongpiozero

I get an Error when I try to round a gpiozero variable


I want to round a variable, but when I run my code it returns the following
Error: "TypeError: type DiskUsage doesn't define __ round __ method". I already looked up in the internet but I didn't found something which can solve my problem. Here is my code:

from gpiozero import DiskUsage

disk = DiskUsage()
disk = round(DiskUsage(),3)
print('Current disk usage: {}%'.format(disk))

I want to round it because the value DiskUsage() returns is too long.


Solution

  • I solved it: First I have to do: disk = DiskUsage() and then: disk = disk.usage and now I'm able to round the variable by using disk = round(disk,3)