title: Reformat the if else conditions in Pyspark Code
body: <p>Can anyone tell me how to reformat the below Pyspark code especially the line  dataframe = spark.read.format(main.FILE_FORMAT).load(read_path) which is coming for ORC,CSV and Parquet file types? I want to take this common line out of if conditions and put outside so that the code becomes efficient.</p>
  <pre><code>    Config={'header':'true','inferschema':'true'}
      spark = SparkSession.builder.getOrCreate()
      reader = reduce(lambda x, y: x.option(y[0], y[1]), Config.items(), spark.read)
      if list(pathlib.Path(table_path).rglob(&quot;**/*.parquet&quot;)):
             if main.FILE_FORMAT == &quot;&quot;:
                 main.FILE_FORMAT = &quot;parquet&quot;
              dataframe = spark.read.format(main.FILE_FORMAT).load(read_path)
      elif list(pathlib.Path(table_path).rglob(&quot;**/*.orc&quot;)):
              if main.FILE_FORMAT == &quot;&quot;:
                  main.FILE_FORMAT = &quot;orc&quot;
              dataframe = spark.read.format(main.FILE_FORMAT).load(read_path)
      elif list(pathlib.Path(table_path).rglob(&quot;**/*.csv&quot;)):
              if main.FILE_FORMAT == &quot;&quot;:
                  main.FILE_FORMAT = &quot;csv&quot;
              dataframe = (
                  reader.format(main.FILE_FORMAT).load(read_path)
              )
      else:
              raise RuntimeError(f&quot;Could not find orc or parquet or csv files&quot;)
      
      return dataframe
  </code></pre>