How to add custom modules in python?

Generally speaking, we will store the python modules we write and the modules that come with python separately to achieve the purpose of easy maintenance.

The Python runtime environment traverses the sys.path list when searching for library files. If we want to register a new class library in the runtime environment, there are three main methods:

Add a new path to the sys.path list.

Set the PYTHONPATH environment variable.

Copy the library file to a directory in the sys.path list (such as the site-packages directory).

In fact, the easiest way is to use .pth files. In the process of traversing the known library file directory, if Python sees a .pth file, it will add the path recorded in the file to the sys.path setting, so that the .pth file says that the specified library can also be used by Python The operating environment is found.

operating:

Create a MyModule.pth file in the Python/Lib/site-package directory, where the content is the path where the customized module is located.

Config code

C:\Project

C:\Project so that the python files in the Project directory can be found.

Python implements custom add save & delete function?

Problem Description:

Now use easygui to make a simple multiple selection interface:

import easygui

rules = easygui.multchoicebox(msg='please choose rules', title='test', choices=['function 1','function 2','custom function'])

Functions 1 and 2 are written and can be realized. This custom function allows users to decide one of the parameters, and the rules have been written in advance. For example, add a string X to the input, this X is for the user to define.

  • The problem now is that after every user-defined function, when using the gui interface again, you need to re-enter it.

Is there a way to save the rules that the user has used before, and can directly select them the next time they are used, or delete them when they are not needed.

If you ignore this easygui framework and just need to realize the idea, how to operate?

Answer: To save, it is physical storage, file format, or database table storage (the pickle library can be used to access simple data), just start the program and read it.

The editor is currently learning Python, so I am more concerned about these related issues. If you are also interested in Python and do not have a professional teacher around you, you can add q878Java788. . 853, let's discuss and study together.

Guess you like

Origin blog.csdn.net/cemaxueyuan/article/details/108393481