my version of @dis.sociat.ing's dollcode algorithm in python

add clipboard support

copy dollcode to the clipboard when the copy (-c) flag is set

+11 -5
+11 -5
main.py
··· 1 1 import argparse 2 2 3 + import pyperclip 4 + 3 5 4 6 def positive_int(val: str): 5 7 ival = int(val) ··· 34 36 return output 35 37 36 38 37 - def print_dollcode(output: list[str]): 39 + def print_dollcode(output: list[str], copy: bool): 38 40 string: str = "" 39 41 40 42 for char in output: 41 43 string += char 42 44 43 - print(string) 45 + if copy: 46 + pyperclip.copy(string) 47 + print(f"{string} -> 📋 copied!") 48 + else: 49 + print(string) 44 50 45 51 46 - def main(number: int): 47 - print_dollcode(convert_number(number)) 52 + def main(number: int, copy: bool): 53 + print_dollcode(convert_number(number), copy) 48 54 49 55 50 56 if __name__ == "__main__": 51 - main(args.number) 57 + main(args.number, args.c)