Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
API design an choice
#1
i am creating a group of functions that have a similar purpose across a list of file paths. i will look at four of them for this question although the answer will be applied more of them later on. these are just examples for the general API question:

1. wait until all files exist
2. wait until any file exists
3. wait until all files do not exist
4. wait until any file does not exist

if these were commands, the way to give such a command a list of files would be to provide them as command line arguments. but since i am making them as Python functions callable by other Python code that has access to their names. one way to design the API is for the files to be provided as individual file arguments called like:

wait_until_all_files_exist(file1,file2,file3)

the other way is to pass a list (or tuple) as a single argument called like:

wait_until_all_files_exist([file1,file2,file3])
wait_until_all_files_exist((file1,file2,file3))

i cannot decide which is best although i am leaning toward a list. that got me to think of allowing either way by testing the type of the first argument. if the first argument is a list (or tuple) then it has all the file names. if the first argument is a string or bytes then all the arguments are individual names. if i include thorough testing, then anything else will raise some more meaningful exception.

i could go more extreme and flatten a list of lists (or tuples) of any depth or even collect all the names from iterators.

what is your opinion on these or other variation of an API that some new functions should use?
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
API design an choice - by Skaperen - Apr-27-2024, 12:58 AM
RE: API design an choice - by Gribouillis - Apr-27-2024, 07:27 AM
RE: API design an choice - by Skaperen - Apr-27-2024, 05:26 PM
RE: API design an choice - by Gribouillis - Apr-28-2024, 06:44 AM
RE: API design an choice - by snippsat - Apr-28-2024, 04:05 PM

Forum Jump:

User Panel Messages

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