Linux   发布时间:2022-03-31  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了platform模块和ctypes模块大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

一、ctypes模块 Python 的 ctypes 要使用 C 函数,需要先将 C 编译成动态链接库的形式,即 Windows 下的 .dll 文件,或者 Linux 下的 .so 文件。先来看一下 ctypes 怎么使用 C 标准库。 Windows 系统下的 C 标准库动态链接文件为 msvcrt.dll (一般在目录 C:\Windows\System32 和 C:\Windows\Sys

一、ctypes模块

Python 的 ctypes 要使用 C 函数,需要先将 C 编译成动态链接库的形式,即 Windows 下的 .dll 文件,或者 Linux 下的 .so 文件。先来看一下 ctypes 怎么使用 C 标准库。

Windows 系统下的 C 标准库动态链接文件为 msvcrt.dll (一般在目录 C:\Windows\System32 和 C:\Windows\SysWOW64 下分别对应 32-bit 和 64-bit,使用时不用刻意区分,Python 会选择合适的)

Linux 系统下的 C 标准库动态链接文件为 libc.so.6 (以 64-bit Ubuntu 系统为例, 在目录 /lib/x86_64-linux-gnu 下)

代码

#例如,以下代码片段导入 C 标准库,并使用 printf 函数打印一条消息
import platform
from ctypes import *

if platform.system() == Windows:
    libc = cdll.LoadLibrary(@H_584_44@msvcrt.dll)
    # libc = windll.LoadLibrary(‘msvcrt.dll‘)
elif platform.system() == Linux:
    libc = cdll.LoadLibrary(libc.so.6)

String=Hello ctypes!\n
libc.printf(String.encode("utf-8"))

二、platform模块

该模块用来访问平台相关属性

常见属性方法

# 返回平台架构
print(platform.machine())# AMD64

# 获取网络名称
print(platform.node())# DESKTop-NR_875_11845@IUQ2D

# 获取系统版本
print(platform.platform())# Windows-10-10.0.17763-SP0

# 获取处理器名称
print(platform.processor())# Intel64 Family 6 Model 142 Stepping 10,GenuineIntel

# 获取系统名称
print(platform.system())# Windows

大佬总结

以上是大佬教程为你收集整理的platform模块和ctypes模块全部内容,希望文章能够帮你解决platform模块和ctypes模块所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:ctypes模块