문제

say in on windows 7 using python language: os.path.expanduser('~') gets me 'E:\Users\san'

and in there is a Documents folder so i can get to it by os.join()

what is it called on MAC OSx or other linux distros?

도움이 되었습니까?

해결책 2

The users directory in UNIX (Mac OS X) and UNIX-like (Linux, et al.) systems is called "Users". In that directory are the account directories. Typically in OS X, you see the one account directory for the owner of the computer, and another called "Shared". The Shared account is read-write access for everyone.

os.path.normpath(os.path.join(os.path.expanduser("~"), "Documents"))

The Documents directory for the logged in user is in the user account directory. For OS 10.4.11 or earlier, there is no default Documents directory. Some installations (MS Office, for example) create a Documents directory in older OS versions. Using UNIX pathway marks for a user called Bob Smith... /Users/bobsmith/Documents

다른 팁

I think it should be mostly the same. The structure in Unix is similiar, therefore

os.path.join(os.path.expanduser("~"), "Documents")

should take you to the folder. If ~ does not work try HOME or $HOME.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top