Python Forum

Full Version: replacing the open function
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
in a script where the builtin open() function does not need to be called, but os.open() does get called, what will happen if os.open is imported over open and the os.open() calls are changed to open() calls (besides the confusion to readers) ?
from os import close,open
If import like that then it will overwrite build in open().
Output:
>>> print(open.__doc__[:115]) Open file and return a stream. Raise OSError upon failure. file is either a text or byte string giving the name ( >>> from os import close,open >>> print(open.__doc__[:115]) Open a file for low level IO. Returns a file descriptor (integer). If dir_fd is not None, it should be a file des
If ever want to use os.open()(never used it).
Then do not import like that,but use import os.
Doc Wrote:Note This function is intended for low-level I/O.
For normal usage, use the built-in function open(),
which returns a file object with read() and write() methods (and many more).
To wrap a file descriptor in a file object, use fdopen().
i've already read recommendations against doing it. but i am asking what will happen when that is done. i already know it will override the builtin open() function. i already know most python programmers will be confused. what else will it do? will it send wilted roses to my mother?