字符串格式化实例PyFormat.zip

时间:2022-08-06 21:48:08
【文件属性】:
文件名称:字符串格式化实例PyFormat.zip
文件大小:19KB
文件格式:ZIP
更新时间:2022-08-06 21:48:08
开源项目 PyFormat 是记录 Python 字符串格式化系统的实例的项目。python.org 的官方文档中,包含了大量的关于格式化语法规范的信息,以及一些例子,但他们的文档太理论和技术化了。这个项目把常用格式化的新老风格直观地展示出来,提供了实际的例子。如果没有特别注明外,所有的例子使用 Python2.7,3.2,3.3,和3.4,而无需任何额外的库或 monkey-patching。基本的格式化:Old'%s %s' % ('one', 'two')New'{} {}'.format('one', 'two')Outputone two数值转换:Setupclass Data(object):     def __str__(self):         return 'str'     def __repr__(self):         return 'repr'Old'%s %r' % (Data(), Data())New'{0!s} {0!r}'.format(Data())Outputstr repr填充和对齐字符串:右对齐:Old's' % ('test',)New'{:>10}'.format('test')Output      test长字符串截位:Old'%.5s' % ('xylophone',)New'{:.5}'.format('xylophone')Outputxylop 标签:PyFormat
【文件预览】:
pyformat.info-master
----main.py(7KB)
----requirements.txt(5B)
----.travis.yml(160B)
----tox.ini(144B)
----LICENSE(1KB)
----assets()
--------sass()
----setup.py(429B)
----README.md(3KB)
----tests()
--------test_content.py(13KB)
--------fixtures()
--------test_main.py(5KB)
--------__init__.py(0B)
----templates()
--------index.html(7KB)
----.gitignore(136B)
----fabfile.py(355B)

网友评论