+-+-+-+-+-+-+
|B|R|U|I|S|E|
+-+-+-+-+-+-+
home | categories | readme
bool
Spending time on the shared Avant Whatever server I'm always fascinated by the conditions of presence.
When I SSH into the server I have a series of commands I'm likely to run. I automated these for a while, but missed the tactility. The simple, fragile, input of commands. It's no doubt different for others, but I often log in simply to run htese commands, moving between a handful of directories. I guess I'm checking in - to see if it is still there - if there really is a tiny server on the other side of the world that I can write to.
Anyway, the following is a directory with a couple of files. Running the switch.py script will re-write the .txt file to be either on or off. A message will print confirming the action. So that's it - a switch.
.
├── off.txt
├── readme.txt
└── switch.py
readme.txt
run
python switch.py
to toggle the switch.
switch.py
import os
# Absolute path of a file
old_name = r"on.txt"
new_name = r"off.txt"
success = "You toggled the switch."
# Renaming the file
if (os.path.exists(old_name)):
os.rename(old_name, new_name)
print(success)
else:
os.rename(new_name, old_name)
print(success)
off.txt
This file could contain anything... I think it has to contain at least a thing. Mine has 'o'.
categories: code
~gg 04/23
+-+-+-+-+-+-+
|B|R|U|I|S|E|
+-+-+-+-+-+-+