zoukankan      html  css  js  c++  java
  • Python3-笔记-E-010-库-漂亮打印(这个是谁给翻译的名字吖。。。)pprint

    import pprint
    #格式化打印
    message = 'It was a bright cold day in April, and the clocks were striking thirteen.'
    count = {}
    for character in message:
    count.setdefault(character, 0)
    count[character] = count[character] + 1
    pprint.pprint(count)

    # 格式化写入内容到py文件,然后在加载当作代码使用
    import pprint
    cats = [{'name': 'Zophie', 'desc': 'chubby'}, {'name': 'Pooka', 'desc': 'fluffy'}]
    pprint.pformat(cats)
    fileObj = open('myCats.py', 'w')
    fileObj.write('cats = ' + pprint.pformat(cats) + ' ')
    fileObj.close()
    import myCats
    print(myCats.cats)
    
    
     
  • 相关阅读:
    哈希表和HashMap内部实现原理
    git入门指导
    eclipse快捷键汇总
    Java Map容器小示例
    Java容器小解析
    泛型小解析
    Python UDP编程小示例
    wcf-2
    wcf-1
    感想
  • 原文地址:https://www.cnblogs.com/vito13/p/7736340.html
Copyright © 2011-2022 走看看