0

I'm looking for a way how can I compress python code.

Ideal solution converts

def sum_of_two(first, second):
    ''' sum of two'''
    return first + second

Into

def a(b,c):
    return b+c

Any ideas of ways how I can do it?

Thanks

Oduvan
  • 2,607
  • 3
  • 24
  • 24
  • 3
    You want to look for "python obfuscation". It'll be easy from there. – Scott Mermelstein Mar 24 '17 at 17:35
  • Are you looking for something that looks at the code and rewrites it? – Andria Mar 24 '17 at 17:35
  • Wow, you'll need to parse Python and analyze the code's structure. Good luck with that! See you in two years or later! – ForceBru Mar 24 '17 at 17:36
  • 1
    This is especially tricky to do in Python thanks to its dynamic features. If I do `d = {"first": 23, "second": 42}; print(sum_of_two(**d))`, it will work with the original code but crash after applying a compression algorithm that leaves string literals alone. And a compression algorithm that can determine what string literals should be replaced, would need to have human-level intelligence or above. – Kevin Mar 24 '17 at 17:39
  • Better dupe, but too late: http://stackoverflow.com/questions/261638/how-do-i-protect-python-code – Scott Mermelstein Mar 24 '17 at 17:40

0 Answers0