标签云

微信群

扫码加入我们

WeChat QR Code

This question already has an answer here:

Use of isinstance() changed the class type of dict Why is this happening? I know using builtins would prevent but I want to understand better why this is happening.

250     def printPretty(records,num,title='Summary:'):
251         import pdb; pdb.set_trace()
252         if isinstance(records, list):
253             print ("\n{}\n{}".format(title.center(120),"="*120))
254             table = list()
255             for i in records:
...
263         elif isinstance(records, dict):
264  ->         for key in records:
265                 if isinstance(records[key], Param):
266                     for i in records[key]:
267                         print (i)
268                 print ("")
269     
(Pdb) type(records)
<class 'dict'>
(Pdb) type(dict)
<class 'type'><b>


isinstance won't change the type of things. Nothing here indicates that anything's type has been changed.

2018年08月22日18分16秒

Why do you think any type change has happened?

2018年08月22日18分16秒

Your question suggests that you're expecting some different results from the type calls you're making at the end, but it's not clear what you expect instead. Can you clarify what you expected and why?

2018年08月22日18分16秒

stackoverflow.com/questions/100003/…

2018年08月22日18分16秒

Thank you! That's exactly right, I was confused and your answer clarified.

2018年08月22日18分16秒