Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to introduce File path in python

Shulou Source: shulou.com Published: 2022-05-31 11:13:06 09月23日 Update

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.

Tags: Paths documents knowledge articles methods content different big most that is location more modules knowledge points industry information information channels logic facets projects Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Shulou Information Linux NVidia Redmi