How does python get the absolute path of a file
In this article, the editor introduces in detail the "python how to get the absolute path of the file", the content is detailed, the steps are clear, and the details are handled properly. I hope that this "python how to get the absolute path of the file" article can help you solve your doubts, following the editor's ideas slowly in depth, together to learn new knowledge.
The specific steps are as follows:
1. First, open python and create a new python project
After the 2.python project is created, import the os and inspect modules in the project using the import method
Import os
Import inspect
After the 3.os and inspect modules are imported, use the inspect.getfile () method in the project to get the path of the current file
Path = inspect.getfile (inspect.currentframe ())
4. Finally, after the current path of the file is obtained, the absolute path of the file can be obtained by using os.path.abspath ()
Abspath = os.path.abspath (path)
After reading this, the article "how to get the absolute path of python files" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself to understand it. If you want to know more about related articles, welcome to follow the industry information channel.