2024-04-19 22:56:56 发布
网友
这行代码是什么意思
datafolder = os.path.join(os.path.expanduser("~"), "Data", "books")
这行是否创建了一个名为datafolder的文件夹?如果创建了,我可以在其中插入文件并通过该行加载文件
从文件中:
os.path.expanduser(path)On Unix and Windows, return the argument with an initial component of ~ or ~user replaced by that user‘s home directory.
os.path.expanduser(path)
On Unix and Windows, return the argument with an initial component of ~ or ~user replaced by that user‘s home directory.
在Unix中,主目录由波浪号(~)表示。使用^{}将颚化符展开到实际路径:
~
In [765]: os.path.expanduser("~") Out[765]: '/Users/Coldspeed'
此字符串与'Data'和'books'一起由os.path.join连接在一起,形成一个完全限定的路径:
'Data'
'books'
os.path.join
这是一种不必硬编码就可以指定主目录的方便方法。在
从文件中:
在Unix中,主目录由波浪号(} 将颚化符展开到实际路径:
~
)表示。使用^{此字符串与
^{pr2}$'Data'
和'books'
一起由os.path.join
连接在一起,形成一个完全限定的路径:这是一种不必硬编码就可以指定主目录的方便方法。在
相关问题 更多 >
编程相关推荐