How to remove extra indentation of Python triple quoted multi-line strings?

后端 未结 6 1051
野的像风
野的像风 2020-12-23 14:46

I have a python editor where the user is entering a script or code, which is then put into a main method behind the scenes, while also having every line indented. The proble

6条回答
  •  借酒劲吻你
    2020-12-23 14:59

    The only way i see - is to strip first n tabs for each line starting with second, where n is known identation of main method.

    If that identation is not known beforehand - you can add trailing newline before inserting it and strip number of tabs from the last line...

    The third solution is to parse data and find beginning of multiline quote and do not add your identation to every line after until it will be closed.

    Think there is a better solution..

提交回复
热议问题