Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to split up a long f-string in python?

I am getting a line too long pep8 E501 issue.

f'Leave Request created successfully. Approvers sent the request for approval: {leave_approver_list}' 

I tried using a multi-line string, but that brings in a \n, which breaks my test:

f'''Leave Request created successfully. Approvers sent the request for approval: {leave_approver_list}''' 

How can I keep it single line and pass pep8 linting

like image 434
tread Avatar asked Feb 20 '18 08:02

tread


Video Answer


1 Answers

Use parentheses and string literal concatenation:

msg = (          f'Leave Request created successfully. '          f'Approvers sent the request for approval: {leave_approver_list}' ) 

Note, the first literal doesn't need an f, but I include it for consistency/readability.

like image 133
juanpa.arrivillaga Avatar answered Sep 24 '22 14:09

juanpa.arrivillaga