[Python-Dev] unifying os.rename semantics across platform
Peter Funk
pf@artcom-gmbh.de
Wed, 23 May 2001 09:49:13 +0200 (MEST)
Hi,
Fred L. Drake, Jr. schrieb:
> skip@pobox.com writes:
> > On the (unsupportable) theory that to-date, more Python apps have been
> > written and/or deployed on Unix-like systems and that where Windows apps are
> > concerned, many developers will have added a thin wrapper to mimic the Unix
> > semantics, I think less breakage would result if the Unix semantics were
>
> I don't know whether there are more deployed Python apps on Unix
> than on Windows (and I've no good idea about how to find out), but I
> think unifying the semantics one way or the other is a good thing.
> Regardless of which set of semantics is chosen.
I agree. May I suggest to add an optional third boolean parameter to
os.rename called 'replace', which defaults either to TRUE or FALSE, so
modifying existing apps will become even less hassle to potential porters.
Here is a strawman to explain what I mean:
--------------------------------------
import os
def new_rename(src, dst, replace=0, old_rename=os.rename):
if os.path.exists(dst):
if replace:
if not os.path.isdir(dst):
os.remove(dst)
else:
# I'm not sure what to do here. recursive removal? dangerous!
raise NotImplementedError
else:
raise OSError("%s already exists" % dst)
return old_rename(src, dst)
os.rename = new_rename
--------------------------------------
Regards, Peter
--
Peter Funk, Oldenburger Str.86, D-27777 Ganderkesee, Germany, Fax:+49 4222950260
office: +49 421 20419-0 (ArtCom GmbH, Grazer Str.8, D-28359 Bremen, Germany)