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
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()
>>> psutil.cpu_percent() > 90

Messages In This Thread

Possibly Related Threads…
Thread Author Replies Views Last Post
  Change font in a list or tuple apffal 3 553 Oct-14-2021, 05:26 AM
Last Post: ndc85430
  change csv file into adjency list ainisyarifaah 0 396 Sep-21-2021, 02:49 AM
Last Post: ainisyarifaah
  How to change odd to even numbers in the list? plumberpy 8 975 Aug-08-2021, 11:07 AM
Last Post: plumberpy
  How to invoke a function with return statement in list comprehension? maiya 4 834 Jul-17-2021, 04:30 PM
Last Post: maiya
  An IF statement with a List variable dedesssse 3 753 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 928 May-24-2021, 08:48 AM
Last Post: bowlofred
  Feed List items with Integer euras 9 1,482 May-19-2021, 07:45 PM
Last Post: snippsat
  LIST or ARRAY Comparison and change of value nio74maz 0 746 Dec-21-2020, 05:52 PM
Last Post: nio74maz
Question dict value, how to change type from int to list? swissjoker 3 1,184 Dec-09-2020, 09:50 AM
Last Post: perfringo
  using element on a list as condition statement glennford49 11 2,325 May-21-2020, 12:53 PM
Last Post: hussainmujtaba

Forum Jump:

User Panel Messages

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