pickle problem:cant reload object saved with binary option

Darrell darrell at dorb.com
Sat Jan 1 14:59:13 EST 2000


Out of curiosity I looked into this file mode thing. Sure beats cleaning out
the garage !

Looks like the '+' allows read/write.
>>> open('t','w').write('now is the time')
>>> open('t','r+').write('xx')
>>> print open('t','r').read()
xxw is the time
>>>
For append you have to use 'a'

/////////////////////////////////
gcc\libio\fileops.c function _IO_file_fopen
  switch (*mode++)
    {
    case 'r':
      omode = O_RDONLY;
      read_write = _IO_NO_WRITES;
    // 0x08
      break;
    case 'w':
      omode = O_WRONLY;
      oflags = O_CREAT|O_TRUNC;
      read_write = _IO_NO_READS;
    // 0x04
      break;
    case 'a':
      omode = O_WRONLY;
      oflags = O_CREAT|O_APPEND;
      read_write = _IO_NO_READS|_IO_IS_APPENDING;
    // 0x1004
      break;
    }
  if (mode[0] == '+' || (mode[0] == 'b' && mode[1] == '+'))
    {
      omode = O_RDWR;
      read_write &= _IO_IS_APPENDING;
    // Allows reads and writes.
    // Keeps APPENDING if it was already given.
    // Which is only the 'a'

    }
  fdesc = open (filename, omode|oflags, oprot);

///////////////////////////

#define _IO_IS_APPENDING 0x1000
#define _IO_NO_READS 4 /* Reading not allowed */
#define _IO_NO_WRITES 8 /* Writing not allowd */


Charlene is tired of lame excuses so garage here I come.
--Darrell

----- Original Message -----
From: "Christian Tismer" <tismer at appliedbiometrics.com>
To: "Marshall" <python at scoobysnacks.com>
Cc: <python-list at python.org>
Sent: Saturday, January 01, 2000 1:44 PM
Subject: Re: pickle problem:cant reload object saved with binary option
>
> No-no-no! :-)
> Please understand the following:
> Whenever you use the binary (c)Pickle format under Windows,
> you *always* must use a binary mode for your file, *both*
> for reading and writing.
>






More information about the Python-list mailing list