我想使用pprint的输出来显示复杂的数据结构,但是我想使用日志记录模块而不是stdout来输出它。
ds = [{'hello': 'there'}]
logging.debug( pprint.pprint(ds) ) # outputs as STDOUTpprint.pformat()在该页面上。
                
                  @Lattywayre-并非每个提出这样问题的人都跳过了文档。我阅读了相同的文档,也错过了pformat。在stackoverflow上,您有时还会从其他人的经验中获得一些根本不在文档中的瑰宝。谢谢yee379提出这个问题。
                
                
                  
                    —
                    Mnebuerquox 2014年
                    
                  
                
              
pprint( {}, stream ),但是发现它很尴尬。我本以为类似的东西spprint可能会比pformat(如中c)更好。