Jun-24-2020, 03:37 AM
here is what i am doing that got me to ask some questions and do a bunch of googling. i am creating a class to open a file in a special way. it will also have some more flexible arguments. i am currently calling it
it supports compression or decompression based on the extension in the file path ( '.gz' or '.bz2' or '.xz'). it support 2 positional arguments, the path and mode. it supports a number of new keyword arguments, append=, binary=, mode=, name=, read=, text=, write=. name= is another way to specify the path. mode= is an additional mode specification. the other 5 are logical flags for various individual modes.
for files being written, a temporary file is created in the same directory (so it ends up in the same file system). it is renamed to the intended name when the file is closed.
if the name is given by both positional argument and keyword argument, it must be the same path. if the paths are different, it will raise TypeError. the name may be given as an int representing a file descriptor just like open() does now. path strings may be given as str, bytes, or bytearray.
if the mode is given by both positional argument and keyword argument, the two are combined. this allows some mode letters in one and some in the other. duplicate mode letters are ignored. mode strings may be given as str, bytes, or bytearray.
the mode keyword arguments allow bool and numeric values. modes as separate keyword arguments may be mixed with mode strings if there is no conflict. conflicts will raise TypeError. the value None will be as if that argument was not given.
that is a lot of checking to do. at least it only has to do that once per file being opened.
ztopen()
. i have made a more limited version that works and is now in use by a couple scripts.it supports compression or decompression based on the extension in the file path ( '.gz' or '.bz2' or '.xz'). it support 2 positional arguments, the path and mode. it supports a number of new keyword arguments, append=, binary=, mode=, name=, read=, text=, write=. name= is another way to specify the path. mode= is an additional mode specification. the other 5 are logical flags for various individual modes.
for files being written, a temporary file is created in the same directory (so it ends up in the same file system). it is renamed to the intended name when the file is closed.
if the name is given by both positional argument and keyword argument, it must be the same path. if the paths are different, it will raise TypeError. the name may be given as an int representing a file descriptor just like open() does now. path strings may be given as str, bytes, or bytearray.
if the mode is given by both positional argument and keyword argument, the two are combined. this allows some mode letters in one and some in the other. duplicate mode letters are ignored. mode strings may be given as str, bytes, or bytearray.
the mode keyword arguments allow bool and numeric values. modes as separate keyword arguments may be mixed with mode strings if there is no conflict. conflicts will raise TypeError. the value None will be as if that argument was not given.
that is a lot of checking to do. at least it only has to do that once per file being opened.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.