Custom indent width for BeautifulSoup .prettify()

后端 未结 4 1600
一生所求
一生所求 2020-12-15 17:29

Is there any way to define custom indent width for .prettify() function? From what I can get from it\'s source -

def prettify(self, encoding=No         


        
4条回答
  •  自闭症患者
    2020-12-15 17:54

    If you're using pycharm you can automatically reformat a html-file by pressing:

    ctrl + alt + L

    while having your prettified html-file open in pycharm.

    This will change indentation from one space to 4, or whatever you set for html in Settings>Editor>Code Style>HTML (default = 4).

    https://www.jetbrains.com/pycharm/guide/tips/reformat-code/

    You would have to do this for every html-file you run prettify() on.

    Sorry if I'm reviving an old thread but I had the same problem and found a simple solution.

提交回复
热议问题