array problems.. OverflowError

Discussion in 'Python' started by ashtonn@gmail.com, Jun 8, 2005.

  1. Guest

    How do i fill 1 byte and 4 bytes in a single array? This array contains
    packet information.

    Python code...

    from array import *

    size = 526
    pData = array("B", '\0'* 526)
    # Destination MAC address
    destAddress = FFFFFFFFFFFF
    for i in range(0, len(destAddress), 2):
    pData[i/2] = int(destAddress[i:i+2], 16)

    pattern = 0xAAAAAAAA
    for i in range( 512):
    pData[i+6] = long(pattern, 16)
    print pData

    OverflowError: long int too large to covert to int

    def test(pData.buffer_info()[0])
    ....
    ....
    Any help appreciated.
    -Ashton
    , Jun 8, 2005
    #1
    1. Advertising

  2. You probably want to look at using struct.pack. That will allow you
    to back heterogenious groups of data into a string that can be saved
    to disk or sent over the network. It also does a really good job of
    taking care of byte order for you(if you tell it to).

    -Chris

    On 8 Jun 2005 10:40:43 -0700, <> wrote:
    > How do i fill 1 byte and 4 bytes in a single array? This array contains
    > packet information.
    >
    > Python code...
    >
    > from array import *
    >
    > size = 526
    > pData = array("B", '\0'* 526)
    > # Destination MAC address
    > destAddress = FFFFFFFFFFFF
    > for i in range(0, len(destAddress), 2):
    > pData[i/2] = int(destAddress[i:i+2], 16)
    >
    > pattern = 0xAAAAAAAA
    > for i in range( 512):
    > pData[i+6] = long(pattern, 16)
    > print pData
    >
    > OverflowError: long int too large to covert to int
    >
    > def test(pData.buffer_info()[0])
    > ....
    > ....
    > Any help appreciated.
    > -Ashton
    >
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >



    --
    Christopher Lambacher
    Chris Lambacher, Jun 8, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paolo Alexis Falcone
    Replies:
    3
    Views:
    1,071
    Paolo Alexis Falcone
    Jun 29, 2003
  2. Luke
    Replies:
    3
    Views:
    432
    Duncan Grisby
    Jun 11, 2004
  3. overflowerror!!

    , May 26, 2005, in forum: Python
    Replies:
    3
    Views:
    311
    John Machin
    May 27, 2005
  4. Sheldon
    Replies:
    4
    Views:
    537
    Sheldon
    Jun 23, 2006
  5. Jorgen Bodde
    Replies:
    2
    Views:
    667
    Jorgen Bodde
    Apr 15, 2007
Loading...

Share This Page