Function open () and method os.open () and derivatives for files

1

When creating a file we have two options: use the function open () or use the module method os, accessing the con os.open (). Then we have its derivatives, such as write, close, read; and the same with the module os; os.write, os.read ...

What is the difference between the two methods? Reading the official documentation says that os.open () and its derivatives are for low level, but really do the same.

    
asked by Jogofus 23.12.2016 в 02:58
source

1 answer

1

The first, for being a little more precise, os.open , os.read and os.write are not methods, they are functions in the package os (see comment of @ChemaCortes more below).

The open function allows you to work further away from the operating system you are working on (higher level) while os.open is working directly with the operating system and using its functions so you must write code a little more specific of the platform you are on (it is of lower level). The first allows you to abstract from that kind of thing, the second allows you to have more control (as long as you know what you are doing).

open returns an object that has methods that allow you to manipulate the object. These methods will be one or the other depending on the way you have used to open the file (reading, writing, ...).

os.open returns you a file descriptor and you will be in charge of knowing what what you have opened, how you have opened it and how to manipulate it (what functions you can use on it).

In general, you should always use open .

    
answered by 23.12.2016 в 08:54