Why is there no error when you open the file twice in Python Programming Language ?
▪ Python will not restrict you from opening a file more than once, and in fact
sometimes this is necessary.
Why is there no error when you open the file twice in Python Programming Language ?
▪ Python will not restrict you from opening a file more than once, and in fact
sometimes this is necessary.
For further actions, you may consider blocking this person and/or reporting abuse
Nik L. -
Swapnoneel Saha -
Sm0ke -
Krzysztof Sordyl -
Top comments (4)
My best guess - Athe operating system level it is valid to open a file more than once. So there isn’t a reason for Python to prevent it either.
Exactly David.
Imagine if one process had the ownership of a file descriptor for its entire lifetime. You couldn't open a file in two editors or synchronize content between a writer or a reader. You couldn't even open a file to have multiple writers. Unix pipes wouldn't probably work as well.
If you need lock everyone else out, that should definitely be an explicit request.
There's no real cost to have multiple readers so why block it by default? Locking is needed with multiple writers
Thank you for sharing this✌
stackoverflow.com/questions/489861...