Skip to content

Instantly share code, notes, and snippets.

@knaveightt
Created February 12, 2026 19:26
Show Gist options
  • Select an option

  • Save knaveightt/9d9148b3599f11be5538125f16036bc0 to your computer and use it in GitHub Desktop.

Select an option

Save knaveightt/9d9148b3599f11be5538125f16036bc0 to your computer and use it in GitHub Desktop.
Python Script to Fix *_glyphs.txt settings files for Dungeon Crawl Stone Soup (DCSS)
import sys
modified_lines = []
def write_modified_lines_to_file(filename):
"""
Writes the list of modified lines to the file.
"""
try:
with open(filename, 'w', encoding='utf-8') as file:
file.writelines(modified_lines)
except FileNotFoundError:
print(f"Error: The file '{filename}' was not found.")
except Exception as e:
print(f"An error occurred: {e}")
def print_last_char_unicode(filename):
"""
Reads a file line by line and prints the Unicode code point (hex and decimal)
for the last character of each line.
Stores a modified version of each line with the last character replaced by
the decimal Unicode code point and stores it in a global list to be used
to replace the lines in the file later.
"""
try:
with open(filename, 'r', encoding='utf-8') as file:
for line_num, line in enumerate(file, 1):
# Use rstrip('\r\n') to remove common newline characters
# before finding the last character. If you want to include
# the newline character in the check, remove the rstrip part.
cleaned_line = line.rstrip('\r\n')
if cleaned_line:
last_char = cleaned_line[-1]
code_point = ord(last_char)
print(f"Line {line_num}: Last character is '{last_char}'")
print(f" Hex: 0x{code_point:X}")
print(f" Dec: {code_point}")
# store a modified version of the line with the last char
# replaced by the decimal unicode code point value
modified_line = cleaned_line[:-1] + str(code_point) + '\n'
modified_lines.append(modified_line)
else:
print(f"Line {line_num}: Line is empty (or only contained newline characters), no last character found.")
except FileNotFoundError:
print(f"Error: The file '{filename}' was not found.")
except Exception as e:
print(f"An error occurred: {e}")
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python script_name.py <filename>")
else:
# Pass the filename provided as a command-line argument
print_last_char_unicode(sys.argv[1])
write_modified_lines_to_file(sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment