phpwl 发表于 2020-4-12 18:59:46

pycharm和idle

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

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

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

    def __getattr__(self, item):
      print('getattr')
这是在pycharm的结果
>>>c=C()
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattr
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattribute
getattr
getattribute
这是idle的结果
>>> c=C()
>>> c.x
getattribute
getattr

永恒的蓝色梦想 发表于 2020-4-12 19:07:09

真的奇怪
VSCODE: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'
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'
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'
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'
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'
PS C:\Users\JHZma\Desktop\pyfiles> IDLE>>> C()
<__main__.C object at 0x000001634BB31E20>
>>> C()
<__main__.C object at 0x000001634BB31FD0>
>>> C()
<__main__.C object at 0x000001634BB31D60>
>>> C()
<__main__.C object at 0x000001634BB31E50>一次都没遇到

zltzlt 发表于 2020-4-12 20:21:23

https://fishc.com.cn/thread-144747-1-1.html

_2_ 发表于 2020-4-12 20:24:51

编译器和原生的 IDLE 还是有区别的……

leon_xinxin 发表于 2020-4-12 20:35:28

编译器的问题吧。。。遇到这种情况是不是要以原生idle为主?

陈尚涵 发表于 2020-4-13 13:59:32

没有,我在idle上运行的结果和你一样,再pycharm运行的结果是末尾在加一个None。
页: [1]
查看完整版本: pycharm和idle