Pythonic way to create a long multi-line string

后端 未结 27 2043
滥情空心
滥情空心 2020-11-22 00:47

I have a very long query. I would like to split it in several lines in Python. A way to do it in JavaScript would be using several sentences and joining them with a +<

27条回答
  •  误落风尘
    2020-11-22 00:58

    I like this approach because it privileges reading. In cases where we have long strings there is no way! Depending on the level of indentation you are in and still limited to 80 characters per line... Well... No need to say anything else. In my view the python style guides are still very vague. I took the @Eero Aaltonen approach because it privileges reading and common sense. I understand that style guides should help us and not make our lives a mess. Thanks!

    class ClassName():
        def method_name():
            if condition_0:
                if condition_1:
                    if condition_2:
                        some_variable_0 =\
    """
    some_js_func_call(
        undefined, 
        {
            'some_attr_0': 'value_0', 
            'some_attr_1': 'value_1', 
            'some_attr_2': '""" + some_variable_1 + """'
        }, 
        undefined, 
        undefined, 
        true
    )
    """
    

提交回复
热议问题