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

后端 未结 6 1054
野的像风
野的像风 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 15:09

    So if I get it correctly, you take whatever the user inputs, indent it properly and add it to the rest of your program (and then run that whole program).

    So after you put the user input into your program, you could run a regex, that basically takes that forced indentation back. Something like: Within three quotes, replace all "new line markers" followed by four spaces (or a tab) with only a "new line marker".

提交回复
热议问题