Rename file without overwriting existing files

Steve D'Aprano steve+python at pearwood.info
Wed Feb 1 19:21:23 EST 2017


On Tue, 31 Jan 2017 02:56 am, Grant Edwards wrote:

> On 2017-01-30, Terry Reedy <tjreedy at udel.edu> wrote:
>> On 1/30/2017 8:58 AM, Peter Otten wrote:
>>> Jussi Piitulainen wrote:
>>
>>>> It doesn't seem to be documented.
>>>
>>> For functions with a C equivalent a look into the man page is usually
>>> helpful.
>>
>> Man pages do not exist on Windows.  I suspect that there are more
>> individual Python programs on Windows than *nix.  I am more sure of this
>> as applied to beginners, most of whom have no idea what a 'man' page is
>> (sexist docs? ;-).
> 
> IMO, beginners shouldn't be using the os module.

Do you mean beginners to Python or beginners to programming, or both?


[...]
> I always found the first sentence to be a bit funny:
> 
>      This module provides a portable way of using operating system
>      dependent functionality.
> 
> I understand whay they're tying to say, but I always found it amusing
> to say you're going to provide a portable way to do something
> non-portable.

Fortunately, as Python has matured as a language, it has moved away from
that simplistic "dumb interface to OS specific functions".

For example, os.urandom:

- calls the getrandom() syscall if available;
- fall back on /dev/urandom if not;
- calls CryptGenRandom() on Windows;
- and getentropy() on BSD.

https://docs.python.org/3.6/library/os.html#os.urandom

Similarly, quite a few os functions either come in a pair of flavours, one
returning a string, the other returning bytes, or they take either a byte
argument or a string argument. Some even accept pathlib path objects.


Python is a high-level, platform-independent language, and the more
platform-independent wrappers around platform-dependent functions, the
better.
 

-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.




More information about the Python-list mailing list