Posts: 4,646
Threads: 1,493
Joined: Sep 2016
what kind of test can i apply (or what library should i look at) to be able to detect if a given open file is open for reading? it is passed as an argument to a function so the function does get to directly see how the file was opened.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,646
Threads: 1,493
Joined: Sep 2016
i was wanting how it was opened, not what permissions the file allows me to open. it might be open to a non-file object like:
Output:
lt1a/forums/3 /home/forums 4> python3.8
Python 3.8.10 (default, Nov 14 2022, 12:59:47)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.stdin.mode,sys.stderr.mode,sys.stdout.mode
('r', 'w', 'w')
>>>
lt1a/forums/3 /home/forums 5>
what cases where it may not have a mode attribute?
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,646
Threads: 1,493
Joined: Sep 2016
it's an open file object. i want to see if i can read it without trying to read it. i think i might need the same for write.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,646
Threads: 1,493
Joined: Sep 2016
so, i can just test for mode or a method and if neither exist, just raise an exception saying that readability cannot be determined. that should be workable for most common cases, i think. or am i guessing too far?
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.