Re: Help: Getting Sequences from Files
- Posted by Patrick Barnes <mrtrick at gmail.com> Jul 22, 2004
- 482 views
The problem is that you are trying to use the binary format. Remove the 'b' from your file open calls, and use get(FN) instead of get_bytes. get_bytes is to retreive a 1d sequence of bytes from the file. get will actually find the structure. On Wed, 21 Jul 2004 17:06:32 -0700, Brent O'Gara <d_brent_ogara at comcast.net> wrote: > > I'm trying to learn some (very) basic programming in Euphoria, and I can't > seem to get my sequences back from the files I write them to. > > example: > <eu code> > > include get.e > > integer FN > sequence stuff > > stuff = {{"a","b"},{"c","d"}} > > ? stuff > puts(1, "\n") > > FN = open("D:\\euphoria\\test\\test.wb", "wb") > print(FN, stuff) > close(FN) > > FN = open("D:\\euphoria\\test\\test.wb", "rb") > stuff = get_bytes(FN, 100) > > ? stuff > puts(1, "\n") > > FN = open("D:\\euphoria\\test\\test.wb", "rb") > stuff = gets(FN) > > ? stuff > > </eu code> > > I used all the '?' to see what 'stuff' was looking like at each step of the > process. I tried changing from "wb" to just "w" but it didn't seem to do > anything different. I also changed the "rb" 's to "r" 's, but again, I got > the same results both ways. > > I'd really like to be able to get 'stuff' to come back as > '{{"a","b"},{"c","d"}}' even '{{{97},{98}},{{99},{100}}}' would work. When > I read the file back into the sequence I get > '{123,123,123,57,55,125,44,123,57,56,125,125,44,123,123,57,57,125,44,123,49, > 48,48,125,125,125}' which does not help me at all. I recognise that it has > simply changed the '{' into '123' etc, but I don't know how to get it back. > > I'm looking for a way to send a sequence of sequences out to a file, and > then later retrieve the sequence of sequences in the same format that I > originally sent it out in. > Additionally, how do I get it to display '{{{97},{98}},{{99},{100}}}' as > '{{"a","b"},{"c","d"}}' onscreen? (I only need one letter at a time, and > It's just an example sequence, so how do I get it to print 'stuff[1][2]' as > 'b' and not '98'?) > > Thanks for any help anyone can give me. The last time I had to write a > working program was in middle school using apple basic on an apple 2e. So > I'm feeling kinda overwhelmed. I recognize most of what Euphoria is capable > of doing, but I can't seem to figure out which commands do it. > > what I'm attempting to accomplish with this is to be able to take several > 256color bitmaps with the same pallette, and turn them into 1 file which > contains a sequence 'x', where 'x[1]' is the first image, 'x[2]' is the > second image, and so on, while the pallette is in another file altogether. > > Thank-you all! > > -Brent O' > > > > -- MrTrick