鱼C论坛

 找回密码
 立即注册
查看: 1036|回复: 5

pycharm和idle

[复制链接]
发表于 2020-4-12 18:59:46 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
请问一下,为什么同样的代码在pycharm和idle里结果却是不一样的
这是代码:
  1. class C:
  2.     def __getattribute__(self, item):
  3.         print('getattribute')
  4.         return super().__getattribute__(item)

  5.     def __setattr__(self, key, value):
  6.         print('setattr')
  7.         super().__setattr__(key,value)

  8.     def __delattr__(self, item):
  9.         print('delattr')
  10.         super().__delattr__(item)

  11.     def __getattr__(self, item):
  12.         print('getattr')
复制代码

这是在pycharm的结果
  1. >>>c=C()
  2. getattribute
  3. getattribute
  4. getattribute
  5. getattribute
  6. getattribute
  7. getattribute
  8. getattribute
  9. getattribute
  10. getattribute
  11. getattribute
  12. getattribute
  13. getattribute
  14. getattribute
  15. getattribute
  16. getattribute
  17. getattr
  18. getattribute
  19. getattribute
  20. getattribute
  21. getattribute
  22. getattribute
  23. getattribute
  24. getattribute
  25. getattr
  26. getattribute
复制代码

这是idle的结果
  1. >>> c=C()
  2. >>> c.x
  3. getattribute
  4. getattr
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-4-12 19:07:09 | 显示全部楼层
真的奇怪
VSCODE:
  1. PS C:\Users\JHZma\Desktop\pyfiles>  ${env:DEBUGPY_LAUNCHER_PORT}='1786'; & 'D:\PYTHON\python.exe' 'c:\Users\JHZma\.vscode\extensions\ms-python.python-2020.3.71659\pythonFiles\lib\python\debugpy\no_wheels\debugpy\launcher' 'c:\Users\*\Desktop\pyfiles\temp.py'
  2. PS C:\Users\JHZma\Desktop\pyfiles>  ${env:DEBUGPY_LAUNCHER_PORT}='1791'; & 'D:\PYTHON\python.exe' 'c:\Users\JHZma\.vscode\extensions\ms-python.python-2020.3.71659\pythonFiles\lib\python\debugpy\no_wheels\debugpy\launcher' 'c:\Users\*\Desktop\pyfiles\temp.py'
  3. PS C:\Users\JHZma\Desktop\pyfiles>  ${env:DEBUGPY_LAUNCHER_PORT}='1795'; & 'D:\PYTHON\python.exe' 'c:\Users\JHZma\.vscode\extensions\ms-python.python-2020.3.71659\pythonFiles\lib\python\debugpy\no_wheels\debugpy\launcher' 'c:\Users\*\Desktop\pyfiles\temp.py'
  4. PS C:\Users\JHZma\Desktop\pyfiles>  ${env:DEBUGPY_LAUNCHER_PORT}='1799'; & 'D:\PYTHON\python.exe' 'c:\Users\JHZma\.vscode\extensions\ms-python.python-2020.3.71659\pythonFiles\lib\python\debugpy\no_wheels\debugpy\launcher' 'c:\Users\*\Desktop\pyfiles\temp.py'
  5. PS C:\Users\JHZma\Desktop\pyfiles>  ${env:DEBUGPY_LAUNCHER_PORT}='1803'; & 'D:\PYTHON\python.exe' 'c:\Users\JHZma\.vscode\extensions\ms-python.python-2020.3.71659\pythonFiles\lib\python\debugpy\no_wheels\debugpy\launcher' 'c:\Users\*\Desktop\pyfiles\temp.py'
  6. PS C:\Users\JHZma\Desktop\pyfiles>
复制代码
IDLE
  1. >>> C()
  2. <__main__.C object at 0x000001634BB31E20>
  3. >>> C()
  4. <__main__.C object at 0x000001634BB31FD0>
  5. >>> C()
  6. <__main__.C object at 0x000001634BB31D60>
  7. >>> C()
  8. <__main__.C object at 0x000001634BB31E50>
复制代码
一次都没遇到
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-4-12 20:21:23 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-4-12 20:24:51 From FishC Mobile | 显示全部楼层
编译器和原生的 IDLE 还是有区别的……
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-4-12 20:35:28 | 显示全部楼层
编译器的问题吧。。。遇到这种情况是不是要以原生idle为主?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-4-13 13:59:32 | 显示全部楼层
没有,我在idle上运行的结果和你一样,再pycharm运行的结果是末尾在加一个None。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-5-20 19:12

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表