您现在的位置是:课程教程文章
python pprint.pformat()函数的使用
2023-12-14 20:33课程教程文章 人已围观
1、返回要打印的内容的文本字符串,这个字符串既易于阅读,也是语法上正确的Python代码。
importpprint cats=[{'name':'Zophie','desc':'chubby'},{'name':'Pooka','desc':'fluffy'}] pprint.pformat(cats) fileObj=open('myCats.py','w') fileObj.write('cats='+pprint.pformat(cats)+'\n') fileObj.close()
2、如果来自pprint.pformat()的字符串保存为.py文件,该文件就是可以导入的模块。
importmyCats myCats.cats myCats.cats[0] myCats.cats[0]['name']
以上就是python pprint.pformat()函数的使用,希望对大家有所帮助。更多Python学习指路:python基础教程
本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。
课程教程:python pprint.pformat()函数的使用上一篇:php中PCRE2的使用
下一篇:没有了