What is the function of os.path.expanduser in python
What is the role of os.path.expanduser in python, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.
On linux, my account is kwsy, and the user's home directory is / home/kwsy. The following code shows how to use the expanduser function.
Python 3.7.0 (default, Jun 28 2018, 13:15:42)
[GCC 7.2.0]:: Anaconda, Inc. On linux
Type "help", "copyright", "credits" or "license" for more information.
> import os
> os.path.expanduser ('~ / .config /')
'/ home/kwsy/.config/'
In the directory ~ / .config/, ~ this is the representative of the user's home directory. If your account is sheng, then in shell, ~ / .config/ is equivalent to / home/sheng/.config,shell will help you find the absolute address of the directory, but in the python program, this equivalence relation is not true. Executing os.mkdir ('~ / test') will report an error, and python cannot recognize ~ / test as / home/sheng/test. You can use the expanduser function to replace ~ with the current user's hone working directory.
Under windows, my account name is zhangdongsheng and my working directory is C:\ Users\ zhangdongsheng
Python 3.6.8 (tags/v3.6.8:3c6b436a57, Dec 24 2018, 00:16:47) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
> import os
> os.path.expanduser ('~ / .config /')
C:\\ Users\\ zhangdongsheng/.config/' will it be helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.