Bottom Page

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?
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Quote
#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)
Quote
#3
if + means read and write, why can't it be used alone?
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Quote
#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
Quote
#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.
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Quote
#6
it is what it is and has worked for a long time.
Quote
#7
i would have called it 'u' or allowed 'rw'. maybe this is why they didn't let me design it :-)
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Quote

Top Page

Forum Jump:


Users browsing this thread: 1 Guest(s)