推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
wave4yy
V2EX  ›  Python

想请教一下, python2 和 3 在 ctype 上的差异

  •  
  •   wave4yy · Oct 22, 2019 · 2943 views
    This topic created in 2529 days ago, the information mentioned may be changed or developed.
    初学 ctypes,试了一段代码
    from ctypes import *
    import win32con

    k32 = windll.kernel32

    size = 20
    sa = k32.LocalAlloc(win32con.LMEM_FIXED, size)
    if sa == 0:
    print("Memory Alloc Failed")
    else:
    print("sa: {}".format(hex(sa)))

    发现这段代码在 python2 中申请的地址都是 c_int32 型,而在 python3 申请的内存地址都是 c_int64 型,有时候还会有 ffff 开头的地址

    python2 版本为 Python 2.7.16 [MSC v.1500 64 bit (AMD64)] on win32
    python3 版本为 Python 3.7.5 [MSC v.1916 64 bit (AMD64)] on win32

    想问一下这是由什么原因导致的,有没有什么解决办法?
    2 replies  •  2019-10-23 12:15:20 +08:00
    imiao
        1
    imiao  
       Oct 22, 2019 via Android
    你装的 python2 和 3 都是 64 位的吗?
    wave4yy
        2
    wave4yy  
    OP
       Oct 23, 2019
    @imiao 是的

    python2 版本为 Python 2.7.16 [MSC v.1500 64 bit (AMD64)] on win32
    python3 版本为 Python 3.7.5 [MSC v.1916 64 bit (AMD64)] on win32
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   949 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 19:02 · PVG 03:02 · LAX 12:02 · JFK 15:02
    ♥ Do have faith in what you're doing.