How to introduce File path in python
Today, I would like to share with you how to introduce the file path in python, the content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.
The specific methods are as follows:
1. Use the os.path.abspath (_ _ file_ _) method to introduce the absolute path of the file
Dirname, filename = os.path.split (os.path.abspath (_ _ file_ _))
Os.path.realpath (_ _ file_ _)
two。 Use the os.path.abspath (sys.argv [0]) method to introduce the absolute path of the file
Dirname, filename = os.path.split (os.path.abspath (sys.argv [0]))
Os.path.realpath (sys.argv [0])
3. Use the approot module to introduce the absolute path where the project is located
Import approot
Print (approot.get_root () +'/ FILE/file1.txt')
These are all the contents of the article "how to introduce file paths in python". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.