0

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.

Simon
  • 77
  • 1
  • 7

2 Answers2

0

Its probably because you already set "disk = DiskUsage()". Try this:

from gpiozero import DiskUsage

disk = round(DiskUsage(),3)
print('Current disk usage: {}%'.format(disk))
Klatten
  • 307
  • 3
  • 16
  • Thank you but I doesn't work. It returns the same error again – Simon Jun 10 '20 at 15:56
  • 1
    Does DiskUsage() return a string? If that's the case you need to cast it into an int, like this: disk = round(int(DiskUsage()),3) – Klatten Jun 10 '20 at 15:58
  • 1
    I solved it. I have to do `disk = DiskUsage()` and `disk = disk.usage` and now I'm able to round it : `disk = round(disk,3)`. But thank you the idea to look what typ DiskUsage() is was great. Thank you!@Kremklatt – Simon Jun 10 '20 at 16:14
0

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)

Simon
  • 77
  • 1
  • 7