Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the common string operations in Python

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

Today, I will talk to you about what string operations are commonly used in Python, which may not be well understood by many people. in order to make you understand better, the editor has summarized the following for you. I hope you can get something according to this article.

Install pyinstaller

First install pyinstaller, using the installation command: pip3 install pyinstaller, as shown in the following figure.

Pyinstaller packaging mechanism

The python script we write cannot be run separately from the python interpreter, so when packaging, we will at least package the python interpreter with the script, and similarly, in order for the packaged exe to work properly, we will package all our installed third-party packages to exe.

Even if our project uses only one requests package, we may have installed other n packages, but he doesn't care, because packages and packages are only dependent. For example, we only have one requests package, but the requests package contains some other dependent packages, so for security, we can only package all the third-party packages plus the python interpreter. This is shown in the following figure.

Blue indicates that the package that requests depends on is installed, see!

Pyinstaller package exe

Here, I will take an example of just writing an office automation script for a colleague. The effect of the source code example is shown in the following figure.

1. Let's package the .py file into an exe. Let's cmd directly to the script's directory and execute the command: pyinstaller-F setup.py, as shown in the following figure.

The ps:-F parameter indicates overlay packaging, so that when packaging, no matter how many times we pack, it is up-to-date. Just remember this and fix the command.

2. After the execution is completed, several folders will be generated, as shown in the following figure.

3. In dist, there is an exe program, which is the executable exe program, as shown in the following figure.

4. Let's drag the setup.exe to the directory at the same level as setup.py, and let's run this. The effect is shown in the following figure.

5. In this way, we have finished a packing job, and if someone else needs it, he can still run it even without a python environment.

6. Next, let's pack a package with an interface. Here, I wrote the simplest framework with pyqt5 to see whether the package into exe can run successfully. The effect diagram is shown in the following figure.

We can see that there is a dark window behind, which is a bit awkward, so our packing command needs to be changed.

7. After the implementation of pyinstaller-F-wsetup.py add-w, the dark console will not be displayed, so there will be no demonstration here!

8. But our packaged exe, our icon, is really a little ugly, default, without any of our own style, so how should we change it?

Execute the command: pyinstaller-F-Wmuri wind.ico setup.py, as shown in the following figure.

After reading the above, do you have any further understanding of what string operations are commonly used in Python? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report