我是 Python 新手,正在寻找如何根据 PEP8 标准格式化以下代码:
- 使用 Python 3.5 所以
fstrings不可用。 - 有了所有的
.format(),很难知道在哪里分割线。
未格式化:
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)
这是我想做的(执行良好):
- 对我来说,这很好地排列了
hist_query过滤器参数 - 还可以很好地排列
file_pathformat()参数
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
))
但是这种格式符合 Python PEP8 标准吗?.在某些行的末尾有悬垂的感觉是违反直觉的。