4 down vote accepted You misunderstood what \xhh does in Python strings. Using \x notation in Python strings is just syntax to produce certain codepoints. You can use '\x61' to produce a string, or you can use 'a'; both are just two ways of saying gi…
Python 读取写入配置文件 —— ConfigParser Python 读取写入配置文件很方便,可使用内置的 configparser 模块:可查看源码,如博主本机地址: “C:/python27/lib/configparser.py” Configuration file parser. A setup file consists of sections, lead by a "[section]" header, and followed by "name: …
Python2随机写入二进制文件: with open('/python2/random.bin','w') as f: f.write(os.urandom(10)) 但使用Python3会报错: TypeError:must be str, not bytes 原因为:Python3给open函数添加了名为encoding的新参数,而这个新参数的默认值却是'utf-8'.这样在文件句柄上进行read和write操作时,系统就要求开发者必须传入包含Unicode字符的实例,而不接受包含二进制数…