D
D
denislysenko2021-10-04 14:17:11
Python
denislysenko, 2021-10-04 14:17:11

How to write a condition in python where multiple checks can be true?

There is a function in which there is a condition if, elif, else
But here it can be such that everything (if, elif and the second elif) can be true.
How to rewrite the condition so that if if, elif and the second elif are true, all operations that match these conditions are performed?

def main():
    if args.csv2parquet is not None:
        csv_to_parquet(args.csv2parquet[0], args.csv2parquet[1])
    elif args.parquet2csv is not None:
        parquet_to_csv(args.parquet2csv[0], args.parquet2csv[1])
    elif args.get_schema is not None:
        print(get_schema(args.get_schema))
    else:
        print('type: python3 convert.py --help')

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
alexbprofit, 2021-10-04
@alexbprofit

try:
  csv_to_parquet(args.csv2parquet[0], args.csv2parquet[1])
  parquet_to_csv(args.parquet2csv[0], args.parquet2csv[1])
  print(get_schema(args.get_schema))
except Exception:
  print('type: python3 convert.py --help')

S
ScriptKiddo, 2021-10-04
@ScriptKiddo

def all_args_is_none(args_list: list) -> bool:
    return all(True if _ is None else False for _ in args_list)


def main():
    if args.csv2parquet is not None:
        csv_to_parquet(args.csv2parquet[0], args.csv2parquet[1])
    if args.parquet2csv is not None:
        parquet_to_csv(args.parquet2csv[0], args.parquet2csv[1])
    if args.get_schema is not None:
        print(get_schema(args.get_schema))

    if all_args_is_none(args_list=[args.csv2parquet, args.parquet2csv, args.get_schema]):
        print('type: python3 convert.py --help')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question