1
我有以下代碼在linux下工作。我想將它移植到Windows
,但我不知道在哪裏尋找。
將基於ctypes的代碼片段從linux移植到windows
import os
import sys
import ctypes
import ctypes.util
MAX_CHARS = 1000 # maximum number of characters to read
if __name__ == "__main__":
libc = ctypes.CDLL("libc.so.6") # LINUX
fd = libc.open(sys.argv[0], os.O_RDONLY)
buffer = " " * MAX_CHARS
num_chars_read = libc.read(fd, buffer, MAX_CHARS)
print buffer[:num_chars_read]
libc.close(fd)
# ALL OF THIS GIVES WRONG DLL's 'UNDER WINDOWS
#libc = ctypes.CDLL(ctypes.util.find_library('c'))
#libc = ctypes.windll.kernel32 # WINDOWS
#libc = ctypes.windll.user32 # WINDOWS
#libc = ctypes.windll.shell32 # WINDOWS
#libc = ctypes.windll.gdi32 # WINDOWS
#libc = ctypes.cdll.msvcrt # WINDOWS
在DLL我需要尋找「開放」和「讀」調用的任何想法?
非常感謝
爲什麼不使用Python內置的I/O工具? – delnan 2011-02-02 14:46:28
你爲什麼用libc打開並讀取文件? Python有這樣做的本地設施。 – 2011-02-02 14:56:53