【发布时间】:2021-09-20 00:28:54
【问题描述】:
我是 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 标准吗?让. 悬挂在某些行的末尾感觉有悖常理。
【问题讨论】:
-
如果您是 Python 新手,为什么要使用 Python 3.5?它已经严重过时了。
-
Databricks 5.5LTS is "stuck" on 3.5。我不愿意团结起来并通过企业国会法案来更新集群:)。您对代码格式有何看法?
-
@Nat Riddle 它还不到 1 岁,已经快 6 岁了!
标签: python code-formatting pep8