Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
here is what i am doing
#1
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 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.
Reply


Messages In This Thread
here is what i am doing - by Skaperen - Jun-24-2020, 03:37 AM
RE: here is what i am doing - by Gribouillis - Jun-24-2020, 05:55 AM
RE: here is what i am doing - by Skaperen - Jun-29-2020, 05:54 PM
RE: here is what i am doing - by Skaperen - Jun-25-2020, 02:54 AM
RE: here is what i am doing - by Skaperen - Jun-25-2020, 05:48 AM
RE: here is what i am doing - by Gribouillis - Jun-25-2020, 06:33 AM
RE: here is what i am doing - by Skaperen - Jun-26-2020, 01:04 AM
RE: here is what i am doing - by Gribouillis - Jun-26-2020, 07:30 AM
RE: here is what i am doing - by Skaperen - Jun-26-2020, 05:52 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020