elementary tuple question. (sorry)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steven W. Orr

    #1

    elementary tuple question. (sorry)

    I have a tuple that I got from struct.unpack. Now I want to pass the data
    from the returned tuple to struct.pack
    >>fmt
    'l 10l 11i h 4h c 47c 0l'
    >>>struct.pack( fmt, tup)
    Traceback (most recent call last):
    File "<stdin>", line 1, in ?
    struct.error: required argument is not an integer

    What's the idiom to pass the data in tup?

    TIA

    --
    Time flies like the wind. Fruit flies like a banana. Stranger things have .0.
    happened but none stranger than this. Does your driver's license say Organ ..0
    Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
    individuals! What if this weren't a hypothetical question?
    steveo at syslang.net
  • attn.steven.kuo@gmail.com

    #2
    Re: elementary tuple question. (sorry)

    On Apr 5, 2:08 pm, "Steven W. Orr" <ste...@syslang .netwrote:
    I have a tuple that I got from struct.unpack. Now I want to pass the data
    from the returned tuple to struct.pack
    >
    >fmt
    >
    'l 10l 11i h 4h c 47c 0l'>>>struct.pa ck(fmt, tup)
    >
    Traceback (most recent call last):
    File "<stdin>", line 1, in ?
    struct.error: required argument is not an integer
    >
    What's the idiom to pass the data in tup?
    >

    Try

    mystring = struct.pack(fmt , *tup)

    --
    Hope this helps,
    Steven

    Comment

    • 7stud

      #3
      Re: elementary tuple question. (sorry)

      On Apr 5, 3:08 pm, "Steven W. Orr" <ste...@syslang .netwrote:
      I have a tuple that I got from struct.unpack. Now I want to pass the data
      from the returned tuple to struct.pack
      >
      >fmt
      >
      'l 10l 11i h 4h c 47c 0l'>>>struct.pa ck(fmt, tup)
      >
      Traceback (most recent call last):
      File "<stdin>", line 1, in ?
      struct.error: required argument is not an integer
      >
      What's the idiom to pass the data in tup?
      >
      TIA
      >
      import struct

      fmt = "l l"
      result = struct.pack(fmt , 12, 4)

      t = (12, 4)
      result = struct.pack(fmt , *t)
      ---------

      The * unpacks the tuple.

      Comment

      • mik3l3374@gmail.com

        #4
        Re: elementary tuple question. (sorry)

        On Apr 6, 5:31 am, "7stud" <bbxx789_0...@y ahoo.comwrote:
        On Apr 5, 3:08 pm, "Steven W. Orr" <ste...@syslang .netwrote:
        >
        I have a tuple that I got from struct.unpack. Now I want to pass the data
        from the returned tuple to struct.pack
        >
        >>fmt
        >
        'l 10l 11i h 4h c 47c 0l'>>>struct.pa ck(fmt, tup)
        >
        Traceback (most recent call last):
        File "<stdin>", line 1, in ?
        struct.error: required argument is not an integer
        >
        What's the idiom to pass the data in tup?
        >
        TIA
        >
        import struct
        >
        fmt = "l l"
        result = struct.pack(fmt , 12, 4)
        >
        t = (12, 4)
        result = struct.pack(fmt , *t)
        ---------
        >
        The * unpacks the tuple.
        there's an unpack().
        >>struct.unpack (fmt,result)

        Comment

        Working...