Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
open('foo','ab+')
#1
what does this mode really do in open('foo','ab+')? does it work only beyond the end of an existing file?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
'a': file pointer at end of file upon opening
'b': binary mode
'+': read and write
you can read from any point in file, but will have to use fseek to get to front of data you want to read,
and fseek aferwards to return to end of file
data can only be written at end of file (Not absolutely sure on this, but think that's correct)
Reply
#3
if + means read and write, why can't it be used alone?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#4
(Jun-26-2020, 05:23 PM)Skaperen Wrote: if + means read and write, why can't it be used alone?
Because they have written it so + don't work alone.
I guess no need for one mode for + alone,as r w a in combination with + make more sense.
If look at source line 323
case '+':
    if (plus)
        goto bad_mode;
So it goes to bad mode.
>>> open('foo.txt', '+')
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
ValueError: Must have exactly one of create/read/write/append mode and at most one plus
Reply
#5
i'm just seeing it called "read/write". that makes me think it would have read and write modes at the same time. since you can't do 'rw', it would seem like '+' is there to do that. but you have to pick one of 'r' or 'w' to append '+' to really have both.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#6
it is what it is and has worked for a long time.
Reply
#7
i would have called it 'u' or allowed 'rw'. maybe this is why they didn't let me design it :-)
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020