I need a sample program that will put the current CPU MHz in a variable with python. I prefer a short compact program. Thanks in advance.

  • But do you want to check the CPU speed, or do you want to change the speed on the fly?
    – tlfong01
    Oct 28, 2019 at 1:01

1 Answer 1


This is four lines, but here it is anyways. Probably isn't the best way, though. (oh, and in your script remember to use the shebang for python3)

from os import popen
str=popen("vcgencmd measure_clock arm").read()
str = str[str.find("=")+1:-7]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.