I'm working on a python project which should be able to control my backlight brightness. I working with Ubuntu 17.04 and I already locate where the file is that show my backlight brightness
/sys/class/backlight/acpi_video0/brightness
the command that I can use in the bash terminal to change the value is
sudo su -c 'echo 12 > /sys/class/backlight/acpi_video0/brightness'
but I have no clue how to implement this in a py project. Maybe this is also the wrong way to start.
Thank you Guys for probably helping me out.
you can use either
os.system()orsubprocess.Popen()Not really recommended, but I see no harm in it for a personal project where the input isn't coming from an external source.. That being said, one should take care using this, because you will be executing straight from your command line, so anything your CLI can do, this can do. You have been warned.
Using
os.system()(you might have to prepend the path to your shell to the command. This is usually/bin/bashin Linux.):import os os.system('echo "your command goes here"')if that doesn't work, then it should look something like:
os.system('/bin/bash echo "your command goes here"')Using
subprocess.Popen()(again, you might need to prepend the path to your shell before the rest of the command.:import subprocess subprocess.Popen('echo "your command goes here"')Once again, I will say, this is NOT recomended for frequent usage especially where outside sources may affect the output of the command being ran. Only use this when you KNOW what will be input into the command.