Categories
Python Answers

How to obfuscate Python code?

Spread the love

Sometimes, we want to obfuscate Python code.

In this article, we’ll look at how to obfuscate Python code.

How to obfuscate Python code?

To obfuscate Python code, we can use the py_compile option with python.

To use it, we run

python -OO -m py_compile foo.py

to run python with py_compile to compile foo.py into a .pyo file.

A .pyo file is a Python script file that has the obfuscated version of the original code.

Some of the variables names can be recognized in the file and comments and docstrings are stripped out.

Conclusion

To obfuscate Python code, we can use the py_compile option with python.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *