I have a list with fixed size of 10 which i will put CPU percent of my computer with 2 seconds of interval. What i'm trying to do is, removing 1st element shifting each element into previous index of list recording 11th value at last index of list
Below you may see my code. I did some debugging but i'm confused right now. How can i fix this?
__author__ = 'tim'
#-*- coding: utf-8 -*-
import psutil, os, time
def getCpuRate():
myList = [None]*10
myString=" "
myString2 = " "
i = 0
j = 0
while True:
if myList[9] is None:
myList[i] = psutil.cpu_percent(interval=2)
myString = myString + (str(myList[i]) + " ")
i = i+1
print i , myString
#time.sleep(3)
else:
while i>0:
myList[j] = myList[j+1]
#print myList[j+1] , myList[j]
for k in range(len(myList)):
myString2 = myString + (str(myList[k]) + "")
print i , j , myString2
j = j+1
i = i-1
if j >= 9:
myList[j] = psutil.cpu_percent(interval=2)
print i , j , myString2
j -= 1
print "a"
getCpuRate()
'''
mySecondList = getCpuRate()
for x in range(len(mySecondList)):
print mySecondList[x]
'''
print "b"