[FRPythoneers] Can't write to file from sub class

John M. Purser jmpurser at comcast.net
Thu Jul 24 17:19:53 MDT 2003


Hello,

I'm working on a project to translate the transaction numbers for out Point
of Sale (POS) system from one numbering scheme to another.  I did it as an
object oriented project for design exercise.  It's been a lot of fun and I
learned a lot.

Now I have a problem.

My data is in ISAM files all having a common structure with each file having
it's own format(s).  I wrote a super class with 99% of the processing in it
(dim_fil.py) and a sub class (in this case sm0.py) which has to have a data
map (dictionary) and if there is more than one format for the file the sub
class overrides the super class method of determining the format.

Really amazingly simple once I got the idea and stopped fighting the
language and the design model.

Here's my problem.  If I instantiate an object of type SM0 I can read the
SM0 file just fine.  But I can't write to it.  Neither my
WriteFieldsByNumber() function nor directly accessing SM0.myfile.write()
works.  No error message, just doesn't change the file.  However if I
instantiate a dim_file object and open the same sm0.d file with it I CAN
write to it!  I can also open it directly and write to it.  All seemingly
with the same code.

Working interactively I can type:
import struct
from sm0 import sm0
a = sm0('sm0.d', 'edit')
a.seek(517)   #Where the transaction number starts.
a.myfile.write(struct.pack('>I', 444444))    # myfile is the file pointer
a.myfile.tell()
521
# No Error message but looking at the transaction number shows it has not
been changed and neither has anything else.

# Now this works.

import struct
from dim_file import dim_file
a = dim_file('sm0.d', 'edit')
a.seek(517)   #Where the transaction number starts.
a.myfile.write(struct.pack('>I', 444444))    # myfile is the file pointer
a.myfile.tell()
521

# Now the transaction number will have been changed.

############################################

edit is translated into 'rb+' and it's handled by the super class, not the
sub class.  If I open three file handles to sm0.d a, b, c where a is direct,
b is a dim_file, and c is a sm0 then a and b will write to it but c won't.
All three say they're file objects (a or b.myfile or c.myfile) with mode
'rb+'.  I've tried calling the file.flush() method and closeing the file and
reopening it.

I'm absolutely stumped.  Can anyone point me in the right direction?

Thanks for the help.

John Purser
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dim_file.py
Type: application/octet-stream
Size: 6466 bytes
Desc: not available
URL: <http://lists.community.tummy.com/pipermail/frpythoneers/attachments/20030724/64cd7ac7/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sm0.py
Type: application/octet-stream
Size: 23698 bytes
Desc: not available
URL: <http://lists.community.tummy.com/pipermail/frpythoneers/attachments/20030724/64cd7ac7/attachment-0001.obj>


More information about the FRPythoneers mailing list