Recently a friend showed me a unix C program calender that behaves differently depending on if you run the program as
cal
or CAL
. Uppercase shows the calender in one orientation, and lowercase flips it. Python can also detect if the script name is upper or lowercase. Here's a dry example:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import os.path | |
full_filename = sys.argv[0] | |
filename, _ext = os.path.splitext(full_filename) | |
if filename.isupper(): | |
print(filename, 'is uppercase') | |
elif filename.islower(): | |
print(filename, 'is lowercase') | |
else: | |
print(filename, 'is mixed or not handled') |
> python PASSING.py PASSING is uppercase > python passing.py passing is lowercaseI think this is pretty neat.