Re: os.rename on Windows

2016-03-23 Thread eryk sun
On Wed, Mar 23, 2016 at 7:17 AM, Steven D'Aprano wrote: > > According to the documentation, os.rename(original, new) will fail if new > already exists. In 3.3+ you can use os.replace. For POSIX systems it's functionally the same as os.rename. pyosreplace [1] backports os.replace for 2.6, 2.7 and

Re: os.rename on Windows

2016-03-23 Thread sjmsoft
Python 2.7.11 on Windows 7 Enterprise (64-bit machine, 32-bit Python) and two Windows Server 2012 R2 (64-bit machines, both 32-bit and 64-bit Pythons): 183 17 WindowsError(183, 'Cannot create a file when that file already exists') HTH, Steve -- https://mail.python.org/mailman/listinfo/python-

Re: os.rename on Windows

2016-03-23 Thread Steven D'Aprano
On Wed, 23 Mar 2016 11:28 pm, Random832 wrote: > On Wed, Mar 23, 2016, at 08:17, Steven D'Aprano wrote: >> Any Windows users here? >> >> print(e.winerror) # Windows only >> print(e.errno) >> print(repr(e)) > > 183 > 17 > FileExistsError(17, 'Cannot create a file when that file alread

Re: os.rename on Windows

2016-03-23 Thread Random832
On Wed, Mar 23, 2016, at 08:17, Steven D'Aprano wrote: > Any Windows users here? > > print(e.winerror) # Windows only > print(e.errno) > print(repr(e)) 183 17 FileExistsError(17, 'Cannot create a file when that file already exists') Python 3.5.1. -- https://mail.python.org/mailman/l

Re: os.rename on Windows

2016-03-23 Thread Chris Angelico
On Wed, Mar 23, 2016 at 11:17 PM, Steven D'Aprano wrote: > import os > open('a123.junk', 'w') > open('b123.junk', 'w') > try: > os.rename('a123.junk', 'b123.junk') > except OSError as e: > print(e.winerror) # Windows only > print(e.errno) > print(repr(e)) > > os.unlink('a123.junk'

os.rename on Windows

2016-03-23 Thread Steven D'Aprano
Any Windows users here? According to the documentation, os.rename(original, new) will fail if new already exists. Would somebody be kind enough to tell me what OSError is raised? In particular: # Untested. import os open('a123.junk', 'w') open('b123.junk', 'w') try: os.rename('a123.junk', '