簡體   English   中英

如何使用python在Mac OS X中找到文件夾路徑?

[英]How to find a folder path in mac os x using python?

我是Mac OS X(10.10.4)的新手。 我想使用python 2.7編寫代碼,首先我必須檢查文件夾“ Pictures”是否存在,然后將文件保存到其中。 但是,我不知道文件夾路徑。

 folder = "~/usr/my_name/Pictures"

但是,我跑完之后

path.exists(folder)

結果為假。

我應該設置文件夾的路徑是什么?

表示主目錄的~字符是shell約定,不僅在Python中可以直接使用。

使用os.path.expanduser()函數來像shell那樣解釋它:

import os.path

folder = os.path.expanduser("~/usr/my_name/Pictures")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM