1. 字符串不同编码格式的字节数组
-
str='测试'
-
res=bytes(str, encoding='gb2312')
-
print(res)
2. 格式化 C 数组(16 -> 12, 符合 C 代码 80 宽度)
-
# 格式化长数组,16 到 12 宽度
-
last_str = ''
-
with open('a.txt', 'r') as fr, open('b.txt', 'w+') as fw:
-
while True:
-
read_str = fr.readline().strip()
-
if len(read_str) > 0:
-
full_str = last_str + read_str
-
while len(full_str) > 60:
-
write_str = full_str[0:60]
-
full_str = full_str[60:]
-
fw.write(write_str + '\n')
-
last_str = full_str
-
else:
-
fw.write(last_str + '\n')
-
break
-
print('finished');
阅读(204) | 评论(0) | 转发(0) |