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
#2
Have you had a look at this doc?
I don't understand why you are putting the cpu_percent in a list bracket.

#! /usr/bin/env python3
import psutil
from time import sleep

max_pct = 90

cpu_pct = psutil.cpu_percent(interval=0.1)
cpu_pct2 = psutil.cpu_percent(interval=0.1, percpu=True)
counter = 10
while counter != 0:
    print(f'cpu_pct: {cpu_pct} \ncpu_pct2: {cpu_pct2}\n')
    sleep(1)
    counter -= 1
Output:
cpu_pct: 8.5 cpu_pct2: [14.3, 0.0, 14.3, 0.0, 14.3, 0.0, 0.0, 14.3, 0.0, 0.0, 0.0, 0.0] cpu_pct: 8.5 cpu_pct2: [14.3, 0.0, 14.3, 0.0, 14.3, 0.0, 0.0, 14.3, 0.0, 0.0, 0.0, 0.0] cpu_pct: 8.5 cpu_pct2: [14.3, 0.0, 14.3, 0.0, 14.3, 0.0, 0.0, 14.3, 0.0, 0.0, 0.0, 0.0] cpu_pct: 8.5 cpu_pct2: [14.3, 0.0, 14.3, 0.0, 14.3, 0.0, 0.0, 14.3, 0.0, 0.0, 0.0, 0.0] cpu_pct: 8.5 cpu_pct2: [14.3, 0.0, 14.3, 0.0, 14.3, 0.0, 0.0, 14.3, 0.0, 0.0, 0.0, 0.0] cpu_pct: 8.5 cpu_pct2: [14.3, 0.0, 14.3, 0.0, 14.3, 0.0, 0.0, 14.3, 0.0, 0.0, 0.0, 0.0] cpu_pct: 8.5 cpu_pct2: [14.3, 0.0, 14.3, 0.0, 14.3, 0.0, 0.0, 14.3, 0.0, 0.0, 0.0, 0.0] cpu_pct: 8.5 cpu_pct2: [14.3, 0.0, 14.3, 0.0, 14.3, 0.0, 0.0, 14.3, 0.0, 0.0, 0.0, 0.0] cpu_pct: 8.5 cpu_pct2: [14.3, 0.0, 14.3, 0.0, 14.3, 0.0, 0.0, 14.3, 0.0, 0.0, 0.0, 0.0] cpu_pct: 8.5 cpu_pct2: [14.3, 0.0, 14.3, 0.0, 14.3, 0.0, 0.0, 14.3, 0.0, 0.0, 0.0, 0.0]
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply


Messages In This Thread
RE: Change a list to integer so I can use IF statement - by menator01 - Sep-21-2021, 01:24 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Change font in a list or tuple apffal 4 2,635 Jun-16-2023, 02:55 AM
Last Post: schriftartenio
  How to change the datatype of list elements? mHosseinDS86 9 1,912 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,482 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,604 Jun-15-2022, 12:00 PM
Last Post: new_coder_231013
  change csv file into adjency list ainisyarifaah 0 1,480 Sep-21-2021, 02:49 AM
Last Post: ainisyarifaah
  How to change odd to even numbers in the list? plumberpy 8 3,622 Aug-08-2021, 11:07 AM
Last Post: plumberpy
  How to invoke a function with return statement in list comprehension? maiya 4 2,754 Jul-17-2021, 04:30 PM
Last Post: maiya
  An IF statement with a List variable dedesssse 3 7,960 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,491 May-24-2021, 08:48 AM
Last Post: bowlofred
  Feed List items with Integer euras 9 3,852 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