What are the advantages of python's built-in function compile?I don't know when it will be used.

Asked 2 years ago, Updated 2 years ago, 84 views

I use python for my work, but I haven't been able to pursue python deeply yet.
While I was reading the source of a python library, I found a built-in function called compile, and I understood how it works based on the following documents, but I didn't understand how compile was used.

http://www.atmarkit.co.jp/ait/articles/1704/28/news041_3.html
https://docs.python.jp/3/library/functions.html#compile

It is often used like exec(compile()) but it should work without the compile.

For what purpose is Python's built-in function used?Please let me know if you know anything about it.

python python3 python2

2022-09-30 21:31

1 Answers

I think compile() itself is a function that I rarely use, but for example, a Python program that executes Python code by entering it as a string or file.You can do this in exec() and so on, but it's more efficient to have it in the compilation code if you want to do it over and over again.

https://stackoverflow.com/questions/22443939/python-built-in-function-compile-what-is-it-used-for


2022-09-30 21:31

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.