Help please with binary file read

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Stewart Arnold

    #1

    Help please with binary file read

    I'm trying to convert a Real Basic routine into Python and I can't read the
    long integer data from a file.

    Here is the Real Basic code:

    b=f.OpenAsBinar yFile
    b.LittleEndian= True
    i=b.ReadByte
    titles=b.ReadLo ng
    shows=b.ReadLon g
    i=b.ReadLong

    And here is my code:

    db = open('otter.db' , 'rb')
    null = db.read(1) # read empty byte
    titles = db.read(4)
    shows = db.read(4)
    null = db.read(1) # read empty byte

    print titles

    When I print titles I get ascii pictures. How do I convert 'titles' to an
    integer I can loop through?
    Is db.read(4) correct for ReadLong?

    Thanks!

    PS. here's the file I'm working with http://otterprojectonline.info/otter.db



  • Grant Edwards

    #2
    Re: Help please with binary file read

    On 2006-01-01, Stewart Arnold <stewartarnold@ DELETEIT.yahoo. com> wrote:
    [color=blue]
    > I'm trying to convert a Real Basic routine into Python and I
    > can't read the long integer data from a file.[/color]

    Source code: Lib/struct.py This module converts between Python values and C structs represented as Python bytes objects. Compact format strings describe the intended conversions to/from Python valu...


    --
    Grant Edwards grante Yow! Here I am in 53
    at B.C. and all I want is a
    visi.com dill pickle!!

    Comment

    • Stewart Arnold

      #3
      Re: Help please with binary file read

      Grant

      Perfect!

      Thanks :)
      Stewart

      "Grant Edwards" <grante@visi.co m> wrote in message
      news:11rfulu5nd q26ff@corp.supe rnews.com...[color=blue]
      > On 2006-01-01, Stewart Arnold <stewartarnold@ DELETEIT.yahoo. com> wrote:
      >[color=green]
      >> I'm trying to convert a Real Basic routine into Python and I
      >> can't read the long integer data from a file.[/color]
      >
      > http://docs.python.org/lib/module-struct.html[/color]


      Comment

      Working...