0

I have written python code and saved as program.py file.Now When i open "program.py" file it should be unreadable format.

Can anyone suggest me how to fix this issue.

1
  • Maybe this link can help you out: link Commented Dec 4, 2017 at 15:37

2 Answers 2

4

You can creat pyc file with compileall:

Put your python files in a folder and run the command in this folder:(Source)

python -m compileall .

This command will produce a pyc file in __pycache__ folder. You can use this file like other python files:(Source)

python myfile.pyc
Sign up to request clarification or add additional context in comments.

2 Comments

You can still read the .pyc file and some import info is seen as well using Linux "cat" command
@manjesh23 Yes, strings and docstring are also readable, but its priority is not hiding the code. pyc files contain the bytecode to speed up the process for the next run. However, it is not readable in general.
0

One way to do that is by compiling the source code using the py_compile module:

python -m py_compile my-py-source.py

The compiled source code will be in _pycache/my-py-source.pyc (relative to your current directory). And the code will still run normally when you run python my-py-source.pyc.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.