Is there a Python equivalent to Perl's Data::Dumper for inspecting data structures?

前端 未结 11 1360
小鲜肉
小鲜肉 2020-12-10 00:19

Is there a Python module that can be used in the same way as Perl\'s Data::Dumper module?

Edit: Sorry, I should have been clearer. I was mainly afte

11条回答
  •  长情又很酷
    2020-12-10 00:54

    I think the closest you will find is the pprint module.

    >>> l = [1, 2, 3, 4]
    >>> l.append(l)
    >>> d = {1: l, 2: 'this is a string'}
    >>> print d
    {1: [1, 2, 3, 4, [...]], 2: 'this is a string'}
    
    >>> pprint.pprint(d)
    {1: [1, 2, 3, 4, ],
     2: 'this is a string'}
    

提交回复
热议问题