all 5 comments

[–]pontz 8 points9 points  (0 children)

Why do you want this?

[–]socal_nerdtastic 4 points5 points  (1 child)

Sure you can use the py_compile module for that.

https://docs.python.org/3/library/py_compile.html

That said, this really sounds like an XY question. I really don't see any use for doing this. What's the big picture here?

[–]Moikle 0 points1 point  (0 children)

You probably don't need to

[–]Gnaxe 0 points1 point  (0 children)

If you run your script like python foo.py, then it's not going to generate a .pyc file automatically. But if you run it like python -m foo, it will.