2009-11-09 56 views

回答

32

在Python,這將是ValueError,或它的子類。

例如,試圖通過.read()關閉的文件引發「ValueError:關閉文件上的I/O操作」。

9

ValueError適當的聲音對我說:

Raised when a built-in operation or function receives an argument that has the right type but an inappropriate value, and the situation is not described by a more precise exception such as IndexError .

+9

不幸的是,這是指一個方法的參數,而不是對象的狀態...... – 2011-04-12 07:14:52

+1

「不適當的值」足夠模糊,我認爲它適用於將參數傳遞給函數,在某些情況下可以,但由於對象的當前狀態。 – 2011-04-12 12:25:38

+2

如果函數沒有參數會怎麼樣? – 2011-05-15 22:46:38

相關問題