Files
sloppatron/languages/custom/bingbong/py_to_bingbong.py
2025-10-02 13:25:27 +02:00

34 lines
1007 B
Python

import sys
def python_to_bingbong(python_code):
"""
Converts a string of Python code into its BingBong binary representation.
"""
byte_array = python_code.encode('utf-8')
binary_string = ''.join(f'{byte:08b}' for byte in byte_array)
bingbong_code = binary_string.replace('0', '.').replace('1', ',')
return bingbong_code
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python py_to_bingbong.py <python_file>")
sys.exit(1)
python_file = sys.argv[1]
try:
with open(python_file, 'r') as f:
python_code = f.read()
bingbong_code = python_to_bingbong(python_code)
output_file = python_file.replace('.py', '.bb')
with open(output_file, 'w') as f:
f.write(bingbong_code)
print(f"Successfully converted {python_file} to {output_file}")
except FileNotFoundError:
print(f"Error: File not found at '{python_file}'")
sys.exit(1)