I'm new to Python, looking for how to format the code below per PEP8 standards:
- Using Python 3.5 so
fstrings
are not available. - With all the
.format()
, its tough to know where to split the line.
Unformatted:
hist_df = spark.read.format("delta").table("{table}".format(table=selected_table))
hist_query = hist_df.where(col("status")=='{sel_status}'.format(sel_status=selected_status)).where(col("cret_dt") < '{last_date}'.format(last_date=selected_last_date)).drop("cret_ts", "cret_dt")
file_path = "abfss://{cont}@{acct}.dfs.core.windows.net/{folder}/".format(cont=storage_container, acct=storage_account, folder=selected_folder)
Here is what I want to do (which executes fine):
- To me, this lines up the
hist_query
filter parameters nicely - Also lines up the
file_path
format()
parameters nicely
hist_df = spark.read.format("delta").table("{table}".format(table=selected_table))
hist_query = (hist_df.
where(col("status")=='{sel_status}'.format(sel_status=selected_status)).
where(col("cret_dt") < '{last_date}'.format(last_date=selected_last_date)).
drop("cret_ts", "cret_dt"))
file_path = ("abfss://{cont}@{acct}.dfs.core.windows.net/{folder}/".
format(
cont=storage_container,
acct=storage_account,
folder=sel_folder
))
But is this format in line with Python PEP8 standards? It feels counterintuitive to have the .
dangling off the end of some lines.