Python Forum
Change a list to integer so I can use IF statement
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Change a list to integer so I can use IF statement
#4
If you want it to be a number, why are you putting it into a list?

On line 20, you are calling psutil.cpu_percent(), which returns a floating point number. But when you put it in brackets, you put that value into a new list.

>>> type( psutil.cpu_percent() )
<class 'float'>
>>> type( [psutil.cpu_percent()] )
<class 'list'>
Take off the brackets and you have a number that you can compare against an integer.

>>> psutil.cpu_percent()
6.3
>>> psutil.cpu_percent() > 90
False
Reply


Messages In This Thread

Possibly Related Threads…
Thread Author Replies Views Last Post
  Change font in a list or tuple apffal 4 2,699 Jun-16-2023, 02:55 AM
Last Post: schriftartenio
  How to change the datatype of list elements? mHosseinDS86 9 2,006 Aug-24-2022, 05:26 PM
Last Post: deanhystad
  find some word in text list file and a bit change to them RolanRoll 3 1,548 Jun-27-2022, 01:36 AM
Last Post: RolanRoll
  List Creation and Position of Continue Statement In Regular Expression Code new_coder_231013 3 1,675 Jun-15-2022, 12:00 PM
Last Post: new_coder_231013
  change csv file into adjency list ainisyarifaah 0 1,508 Sep-21-2021, 02:49 AM
Last Post: ainisyarifaah
  How to change odd to even numbers in the list? plumberpy 8 3,757 Aug-08-2021, 11:07 AM
Last Post: plumberpy
  How to invoke a function with return statement in list comprehension? maiya 4 2,858 Jul-17-2021, 04:30 PM
Last Post: maiya
  An IF statement with a List variable dedesssse 3 8,295 Jul-08-2021, 05:58 PM
Last Post: perfringo
  Question about change hex string to integer sting in the list (python 2.7) lzfneu 1 2,539 May-24-2021, 08:48 AM
Last Post: bowlofred
  Feed List items with Integer euras 9 3,986 May-19-2021, 07:45 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020