Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #100761
| From | Ben Finney <ben+python@benfinney.id.au> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Why doesn't os.remove work on directories? |
| Date | 2015-12-23 16:02 +1100 |
| Message-ID | <mailman.78.1450846996.2237.python-list@python.org> (permalink) |
| References | <m21tadhjoo.fsf@fastmail.com> |
Random832 <random832@fastmail.com> writes:
> This is surprising to anyone accustomed to the POSIX C remove
> function, which can remove either files or directories. Is there
> any known rationale for this decision?
No, I don't know a rationale for implementing it this way.
I expect the explanation will be “mere historical accident”. My
evidence-free reconstruction of the events leading to the current state
of play:
1. ‘os.unlink’ implemented, using C ‘unlink(3)’. Because ‘unlink(2)’
on a directory will cause an error, Python raises OSError for this.
2. ‘os.remove’ implemented; “This is identical to the unlink() function
documented below.”.
3. Backward compatibility concerns (existing code might depend on
‘os.remove’ raising OSError for a directory argument) justify
keeping the existing behaviour.
What you're looking for amounts to “why was ‘os.remove’ implemented as a
synonym of ‘unlink(3)’ instead of ‘remove(3)’?”.
I don't know why that behaviour was chosen, and I consider it a wart.
--
\ “… no testimony can be admitted which is contrary to reason; |
`\ reason is founded on the evidence of our senses.” —Percy Bysshe |
_o__) Shelley, _The Necessity of Atheism_, 1811 |
Ben Finney
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Why doesn't os.remove work on directories? Ben Finney <ben+python@benfinney.id.au> - 2015-12-23 16:02 +1100
csiph-web