mirror of
https://github.com/Alvin-Zilverstand/sloppatron.git
synced 2026-03-06 21:36:29 +01:00
bingbong
This commit is contained in:
33
languages/custom/bingbong/py_to_bingbong.py
Normal file
33
languages/custom/bingbong/py_to_bingbong.py
Normal file
@@ -0,0 +1,33 @@
|
||||
|
||||
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)
|
||||
Reference in New Issue
Block a user