Python: How to style declarations of multiple variables (of different name lengths)

Viewed 61

I am looking for the cleanest way to declare multiple variables in Python. My code looks like this:

app_type = config_data["app"]
app_params = config_data["app_data"]
original_fps = config_data["main"][0]["original_fps"]
sub_sampled_fps = config_data["main"][0]["sub_sampled_fps"]
max_retries = config_data["main"][0]["max_retries"]
win_size = config_data["main"][0]["window_size"]
input_frame_rate = config_data["main"][0]["input_frame_rate"]

Is something like this acceptable by the styling guide?

app_type            = config_data["app"]
app_params          = config_data["app_data"]
original_fps        = config_data["main"][0]["original_fps"]
sub_sampled_fps     = config_data["main"][0]["sub_sampled_fps"]
max_retries         = config_data["main"][0]["max_retries"]
win_size            = config_data["main"][0]["window_size"]
input_frame_rate    = config_data["main"][0]["input_frame_rate"]

If not are there any better ways to style it?

1 Answers

Not recommended according to pep8:

# Correct:
x = 1
y = 2
long_variable = 3

# Wrong:
x             = 1
y             = 2
long_variable = 3

See the reference here

Related