我有問題,列出當前用戶的主目錄,而不知道它的絕對路徑。我試着用下面的,但它不工作:列出主目錄沒有絕對路徑
[[email protected] source]# python
Python 2.6.6 (r266:84292, Dec 7 2011, 20:38:36)
[GCC 4.4.6 20110731 (Red Hat 4.4.6-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.listdir('/root')
['python', '.bashrc', '.viminfo']
>>> os.listdir('~')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OSError: [Errno 2] No such file or directory: '~'
>>>
謝謝你的快速回答! –