您当前的位置: 首页 >  Python

嗨学编程

暂无认证

  • 0浏览

    0关注

    1405博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Python3几个常见问题的处理方法

嗨学编程 发布时间:2019-04-27 16:43:38 ,浏览量:0

1. 编码问题:

遇到了几个字符串转换问题,总结如下:

# str to bytes 
str.encode(s)
# bytes to str 
bytes.decode(b)

判断编码方式可用chardet模块的chardet.detect(content)来协助。

2. char *有地址取内容:

strcontent = string_at(addr, -1)

3. 从动态链接库中获取函数并调用ctypes

from ctypes import *
dll = CDLL("YourAPP.dll")
dll.YourFunction()

4. 从dll中调用c程序,返回char*的情况处理

本来在32位下用string_at就可以解决,但是换成64位后内存访问出错。所以改用restype,终于解决。

#32位可行,64位出错:
result = dll.function()
result = string_at(result, -1)
print(result)
#后来改成用restype,32位/64位通用
dll.function.restype = c_char_p
result = dll.function()
print(result)

想要学习Python?Python学习交流群:973783996满足你的需求,资料都已经上传群文件,可以自行下载!

关注
打赏
1663681728
查看更多评论
立即登录/注册

微信扫码登录

0.0535s