Search code examples
pythonsyntaxreadabilitycode-readability

How to split a statement into multiple lines?


What would be the proper Pythonic way to break the first line of the below expression (to appear on multiple lines) so it can be more readable:

if props.getProperty("app.auth.idp.strategy") == '' or props.getProperty("app.auth.idp.strategy") == 'saml/simpleSAMLphp' and PROXYING_MECHANISM == "ngrok":
    IDP_STRATEGY = "saml/simpleSAMLphp"
elif props.getProperty("app.auth.idp.strategy") == 'saml/gsuite':
    IDP_STRATEGY = "saml/gsuite"
elif props.getProperty("app.auth.idp.strategy") == 'saml/remote-simpleSAMLphp':
    IDP_STRATEGY = "saml/remote-simpleSAMLphp"
else:
     IDP_STRATEGY = "saml"

Solution

  • Probably something like this as per PEP8

    if props.getProperty("app.auth.idp.strategy") == '' \
            or props.getProperty("app.auth.idp.strategy") == 'saml/simpleSAMLphp' \
            and PROXYING_MECHANISM == "ngrok":
        IDP_STRATEGY = "saml/simpleSAMLphp"
    elif props.getProperty("app.auth.idp.strategy") == 'saml/gsuite':
        IDP_STRATEGY = "saml/gsuite"
    elif props.getProperty("app.auth.idp.strategy") == 'saml/remote-simpleSAMLphp':
        IDP_STRATEGY = "saml/remote-simpleSAMLphp"
    else:
         IDP_STRATEGY = "saml"