2013-12-22 103 views
0

我有這樣的:蟒蛇os.open使用,同時打開一個目錄

drwxr-xr-x 8 abc root 4096 Dec 21 19:56 javaprac 

這工作:

>>> fd = os.open(os.getcwd() , os.O_RDONLY) 

但是,爲什麼這兩個失敗:

>>> fd = os.open(os.getcwd() , os.O_RDWR) 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
OSError: [Errno 21] Is a directory: '/home/abc/javaprac' 

>>> fd = os.open(os.getcwd() , os.O_WRONLY) 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
OSError: [Errno 21] Is a directory: '/home/abc/javaprac' 
+6

你爲什麼要直接寫*到目錄節點?你想在這裏做什麼? –

+0

@MartijnPieters我的問題很簡單直接,沒有更深的含義:爲什麼我不能寫入這樣的目錄?爲什麼行爲是這樣的? – abc

回答

2

在Linux上,至少,你不能寫入目錄。

$ echo hello >> . 
bash: .: Is a directory 

您可以從目錄中讀取,那個什麼LSDIR命令做。