Boolean open modes for `open()`

ryofurue
Wed, 17 Jul 2024 18:47:51 +0000
General Usage

I’m trying to understand the keyword arguments write, truncate, . . . , of the open() function. I put a link to the documentation at the end of this message.

Specifically, I want to know

1. What it means if you specify write=true alone. Does it imply truncate?

2. What happens if I specify both write=true and truncate=false without specifying append or with append=false?

It turns out that you need to solve some “equations” to find out the default values of the five boolean keywords.

Does the manual actually pose a mathematical question for the reader to solve?

"Solve the following coupled set of equations:

read == !write,
write == truncate | append,
truncate == !read & write,

where append == false". Then what is the value of create as defined by

create == !read & write | truncate | append

?

Actually, I’ve now solve the coupled equations in my head and I think the answer is write == truncate == !read and the solution isn’t unique: there are two solutions: (write, truncate, read) == (true, true, false) or (false, false, true).

Therefore, when append == false (default value), write==true does imply truncate==true. That’s the answer to question 1 above.

I still don’t know the answer to question 2 above. Would it be overwriting the existing file from the top? (Here I’m remembering Fortran’s position="rewind".)

https://docs.julialang.org/en/v1/base/io-network/

3 posts - 3 participants

Read full topic