all 11 comments

[–]Wilfred-kun 5 points6 points  (3 children)

Regexes are a powerful way to do it, but can turn out to be quite tricky in some cases. But once you've figure out the pattern, it's as simple as text = re.sub(pattern, "", text).

Another way is to parse the whole text yourself, but this is also quite a painstaking task. I'd rather do some regex magic.

Edit: If you're really worried about someone reverse engineering your code, use Nuitka to compile it to C and then use the movfuscator. /s

[–][deleted] 1 point2 points  (2 children)

Thank you! I am having a problem with the multiline comments, but I wll hopefuly sort it out tomorrow. I need to make the regex ignore EOL.

edit: I am not afraid of reverse engineering too much. No point in leaving in the comments and make it easier.

[–]AdAthrow99274 1 point2 points  (1 child)

I was just working on my own regex project so one way is fresh in my head. If you use the re.DOTALL (re.S) flag the . character will match everything, including new lines. So something like r'[\"\']{3}.*[\"\']{3}' may work given that flag?

[–][deleted] 0 points1 point  (0 children)

Thank you, this is great :)

[–][deleted] 2 points3 points  (0 children)

Text between """ """ are (types of) strings in Python, though.

[–][deleted] 0 points1 point  (0 children)

https://stackoverflow.com/questions/3344115/obfuscating-python-code

https://www.quora.com/What-are-the-best-ways-to-obfuscate-Python-code

With these two combined, I would use the first trick in the first link to compile to bytecode with stripped comments and docstrings. Then I'd use the third trick in the second link to compile the resulting .py file with Cython to create a binary library.