Calling other program modules in Python, the import statement is grayed out, and the solution to the error is quoted

1. The called module: my_module.py

Insert picture description here

2. Call the module: function.py

Insert picture description here
It can be seen that the function in the my_module.py file is called in the function.py file. Under normal circumstances, if you want to call a function, you must import the module where it is located, that is, its file name. If you want to use the "c_to_f()" function in the my_module.py file, you must "import my_module".
But as shown in the figure above: "import my_module" is gray, indicating that the reference failed.

3. Solution:

Check the error message first: unused import statement "import my_module"
Insert picture description here
means: unused import statement "import my_module". The reason for this problem is that you must be more specific when specifying functions defined in other modules in Python. One way to solve this problem is to replace this line of code: fahrenheit = c_to_f(celsius) with: fahrenheit = my_module.c_to_f(celsius). In this way, you can see that "import my_module" has become the normal color.
Insert picture description here

Guess you like

Origin blog.csdn.net/qq_43516928/article/details/113488376