zoukankan      html  css  js  c++  java
  • Python 字节流写入文件

    用struct模块

    三个函数 pack()、unpack()、calcsize()

    #  按照给定的格式(fmt),把数据封装成字符串(实际上是类似于c结构体的字节流)
    pack(fmt, v1, v2, ...)
     
    # 按照给定的格式(fmt)解析字节流string,返回解析出来的tuple
    unpack(fmt, string)      
    
    # 计算给定的格式(fmt)占用多少字节的内存
    calcsize(fmt)

    struct 类型表

    FormatC TypePython typeStandard sizeNotes
    x pad byte no value    
    c char string of length 1 1  
    b signed char integer 1 (3)
    B unsigned char integer 1 (3)
    ? _Bool bool 1 (1)
    h short integer 2 (3)
    H unsigned short integer 2 (3)
    i int integer 4 (3)
    I unsigned int integer 4 (3)
    l long integer 4 (3)
    L unsigned long integer 4 (3)
    q long long integer 8 (2), (3)
    Q unsigned long long integer 8 (2), (3)
    f float float 4 (4)
    d double float 8 (4)
    s char[] string 1  
    p char[] string    
    P void * integer   (5), (3)
  • 相关阅读:
    wpf Behavior
    wpf Trigger
    语法糖
    Lambda 表达式
    wpf 3D动画
    IEnumerable接口学习
    Delegates, Events, and Anonymous Methods 委托、事件与匿名方法
    wpf 平滑效果随记
    软件工程第一篇博客
    记考研高数第一课
  • 原文地址:https://www.cnblogs.com/fieldtianye/p/8276598.html
Copyright © 2011-2022 走看看