On Thu, 26 Mar 2015 08:47 pm, Ivan Evstegneev wrote: > > >> -----Original Message----- >> From: Python-list [mailto:python-list- >> bounces+webmailgroups=gmail....@python.org] On Behalf Of Steven >> D'Aprano >> Sent: Thursday, March 26, 2015 01:49 >> To: python-list@python.org >> Subject: Re: Function Defaults - avoiding unneccerary combinations of >> arguments at input >> >> On Thu, 26 Mar 2015 04:43 am, Ivan Evstegneev wrote: >> >> > Hello all , >> > >> > >> > Just a little question about function's default arguments. >> > >> > Let's say I have this function: >> > >> > def my_fun(history=False, built=False, current=False, topo=None, >> > full=False, file=None): >> > if currnet and full: >> > do something_1 >> > elif current and file: >> > do something_2 >> > elif history and full and file: >> > do something_3
[...] > As I said in a previous mail, main purpose of this arguments is to define > what path should be chose. It is actually one xls file that could be > placed into various placed within my folder tree. > > For instance, I have following folder tree: > > data_lib/ > current/ > history/ > built/ > > Say I have "test.xls" that could be in one of those three folders. > I wrote a function that reads it out, and its input arguments just define > where it should be read. So all those "ifs" related to path definition. Perhaps something like this? def my_func(subdir): if subdir not in ("current", "history", "built"): raise ValueError("invalid sub-directory") # Better to use os.path.join, but I'm feeling lazy. path = "path/to/data_lib/" + subdir + "/test.xls" process(path) -- Steven -- https://mail.python.org/mailman/listinfo/python-list