Reputation: 369
# Evaluation result.
train_eval_results = model.evaluate(x_train, [y_train, x_train])
val_eval_results = model.evaluate(x_val, [y_val, x_val])
batch_size = 2
tc = TimeChecker()
### model is from Keras package.
### val_eval_results is a list of 5 float numbers.
content = f"""
train_evaluation_result = {train_eval_results[4]:.4f}
val_evaluation_result = {val_eval_results[4]:.4f}
elapsed_time = {tc.show_elapsed_time()}
batch_size = {batch_size}
"""
### # show_elapsed_time() return a string.
I want to make a readme file which includes the above content. But sometimes part of the variables in {} do not exist. In that situation, i want to fill empty string or "not defined" thing into {}.
Could you help me?
Upvotes: 2
Views: 268
Reputation: 609
I Believe you can use the inline conditional:
f"batch_size = {batch_size if batch_size else ''}"
Upvotes: 5