2014-07-11 15 views
15

object.__dict__ và những nơi khác đã phương pháp ẩn của họ thiết lập để điều như thế này:'Trình bao bọc vị trí' trong python là gì?

<dictproxy {'__add__': <slot wrapper '__add__' of 'instance' objects>, 
'__and__': <slot wrapper '__and__' of 'instance' objects>, 
'__call__': <slot wrapper '__call__' of 'instance' objects>, 
'__cmp__': <slot wrapper '__cmp__' of 'instance' objects>, 
'__coerce__': <slot wrapper '__coerce__' of 'instance' objects>, 
'__contains__': <slot wrapper '__contains__' of 'instance' objects>, 
'__delattr__': <slot wrapper '__delattr__' of 'instance' objects>, 
'__delitem__': <slot wrapper '__delitem__' of 'instance' objects>, 
'__delslice__': <slot wrapper '__delslice__' of 'instance' objects>, 
'__div__': <slot wrapper '__div__' of 'instance' objects>, 
'__divmod__': <slot wrapper '__divmod__' of 'instance' objects>, 
... 

đây là những gì, và những gì họ sử dụng cho?

Edit: Đây là sản phẩm từ:

class A: 
    pass 
b = A() 
print(type(b).__dict__) 
+0

Tôi nghĩ bạn đã rút ngắn biểu diễn không hợp lệ. Đó là 'mappingproxy ({…})'. Đối với một câu trả lời thích hợp, điều này có thể là một sự khác biệt. – kay

+1

Cảm ơn. Tôi là người mà tôi đã thấy pjc

+2

Có một câu trả lời [ở đây] (http://stackoverflow.com/a/19545928/2555451) có thể làm sáng tỏ một chút. – iCodez

Trả lời

3

Đây là một loại nội sử dụng cho một số callables, phương pháp trên class built-in. Nó không thực sự quan trọng tại sao nó khác với một hàm, hay bất kỳ hàm nào khác có thể gọi được. Bạn có thể gọi nó như là một phương thức trên đối tượng giống nhau.

+0

Mặc dù về mặt kỹ thuật, ** không có câu nào trên thực tế trả lời câu hỏi trong tầm tay. ** Bạn có thể có ít nhất liên kết với câu trả lời có thẩm quyền của [driax] (https://stackoverflow.com/users/72476/driax) ] (https://stackoverflow.com/a/19545928/2809027) về chủ đề, mà * không * thực sự trả lời câu hỏi này. '' –

+0

Vui lòng thêm câu trả lời khác '' –

Các vấn đề liên quan