In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how Python converts the code into a flow chart with one click, and the content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
Graphviz is a drawing tool that can automatically layout diagrams, which is opened by Bell Labs. The last time we quickly drew a beautiful system architecture diagram in Python, we mentioned diagrams, and its internal orchestration logic used this open source toolkit.
The project we are going to introduce today is a tool based on Python and Graphviz that can transform source code into a flowchart: pycallgraph.
1. Prepare for
Before you begin, make sure that Python and pip are successfully installed on your computer. Oh, if not, please visit this article: hyperdetailed Python installation Guide for installation. If you use Python for data analysis, you can directly install Anaconda:Python data analysis and mining helper-Anaconda
Open Cmd (start-run-CMD) in Windows environment, and open Terminal (command+ space input Terminal) in Apple system environment, ready to start entering commands to install dependencies.
Of course, I recommend that you use the VSCode editor, Copy the code of this article, and install the dependency module by running commands in the terminal below the editor. What a comfortable thing: the best partner of Python programming-VSCode detailed guide.
Enter the following command at the terminal to install the dependent module we need:
Pip install pycallgraph
If you see Successfully installed xxx, the installation is successful.
For macOS users, please use brew installation:
Brew install graphviz
For windows users, please click the link to download and install:
Https://pythondict.com/go/?url=https://graphviz.gitlab.io/_pages/Download/windows/graphviz-2.38.msi
After the installation is complete, you need to write it to the environment variable:
two。 Generate flowchart
The module can be called in two ways, one is called in the code through the context:
For example, draw a flowchart of our last "Python my World" source code:
After running the Python file, a pycallgraph.png file is generated under the current folder, which is the flow chart of the code:
Another way is to use the command, which can only be run using bash. MacOS users can ignore this problem, but if you are a windows user, please open bash in the following way (take VS Code as an example):
Then open a new terminal through Ctrl + shift + `and you can see the command line started with bash.
Enter the following command to generate a flowchart:
Pycallgraph graphviz -. / you need to generate the .py file of the flowchart.
When finished, a pycallgraph.png file will be generated under the current folder, and this is the flow chart of the code.
Through this method, you can clearly see the call logic in this source code and the running time of each module. It is a very convenient gadget and is very suitable for beginners to learn other people's open source modules. If you have code that needs to be studied, you can try it with this tool, and you may have an unexpected harvest.
About how Python one click to convert the code into the flow chart to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.