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

前端 未结 11 1339
小鲜肉
小鲜肉 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 01:00

    • For serialization, there are many options.

      • One of the best is JSON, which is a language-agnostic standard for serialization. It is available in 2.6 in the stdlib json module and before that with the same API in the third-party simplejson module.

      • You do not want to use marshal, which is fairly low-level. If you wanted what it provides, you would use pickle.

      • I avoid using pickle the format is Python-only and insecure. Deserializing using pickle can execute arbitrary code.

        • If you did use pickle, you want to use the C implementation thereof. (Do import cPickle as pickle.)
    • For debugging, you usually want to look at the object's repr or to use the pprint module.

提交回复
热议问题