A collection of opinions, thoughts, tricks and misc. information.
What's up everyone? I've been reading up a little more on Python... I knew enough to quickly debug runtime errors in python stuff that I downloaded, but never really got into programming with the language. When I decided that I didn't like bash scripting, and needed to get a job done, I turned to CLI PHP... Which is definitely not fun to program with.
I love PHP for web scripting. It's extremely simple to get a quick site off of the ground, and comes available with almost every hosting plan you'd ever look into, but let's face it, PHP is NOT ready for more traditional, single-computer based languages. I read up a little on PHP GTK, which looked interesting, but a little too complicated for my taste. And, by the way, why do I want to rely on a language that's just recently gained good CLI capabilities... I want a full-featured language that I can use for anything. And that's what got me interested enough in python to put some effort into learning it.
So I picked up the Python in a Nutshell book, and started reading. This really is a nice little language. I've written some very simple scripts thus far... This one, my most recent, shows my lack of understanding thus far, but works:
# Simple script for raising, lowering, or directly setting the processor throttling state...
# Takes a single argument, either n, an integer smaller than max_state and larger than min_state,
# or +, which increments the state, or -, which decrements the state.
throttling_file = "/proc/acpi/processor/CPU1/throttling"
max_state = 7
min_state = 0
"Get the processor's current throttle state... "
file = open(throttling_file, "r")
str = file.readline()
if str == "": return None
if str.find("*") > -1:
start = str.find("*") + 2
level = str[start:start+1]
if state == "+":
state = str(getcurrentstate() + 1)
elif state == "-":
state = str(getcurrentstate() -1)
if int(state) > max_state or int(state) < min_state:
print "Cannot set specified state. State remains at %i" % getcurrentstate()
print "Setting processor throttling to level %s" % state
os.system("echo -n %s > %s" % (state,throttling_file))
if len(sys.argv) <> 2:
print "Setting processor throttling to default, state 0. Only call this script with one argument."
state = "0"
state = sys.argv
All it does is set my processor's throttling... I can pass a throttling level, or a + / -, and it will adjust the processor level accordingly... I could add quite a bit more, but it does what I need. I've bound it to keyboard shortcuts, and can throttle my processor as I feel fit... Good stuff... I'll be back,