推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
pmispig
V2EX  ›  Python

请问怎么更改 string.format()所用的{}

  •  
  •   pmispig · May 20, 2020 · 3115 views
    This topic created in 2328 days ago, the information mentioned may be changed or developed.
    可以改成 {{ }} 或者 {% %} 吗
    Supplement 1  ·  May 20, 2020
    因为 shell 脚本里很多 {}了,要从 format 格式化,找了半天也没好得,jinja2 又和其他得字符冲突了,自己用正则写了一个 Template
    5 replies  •  2020-05-21 11:53:02 +08:00
    ClericPy
        1
    ClericPy  
       May 20, 2020
    string.format() 之前看的是不支持自定义定界符的, 现在不确定

    如果不是太纠结 .format 的话, string.Template 有个 delimiter 考虑继承后改它, 或者考虑 jinja2 等其他库

    之前翻过没找到什么太好的
    rayhy
        2
    rayhy  
       May 20, 2020 via Android
    要不再写一个替换函数。。运行 format 之前先把{%替换成{{
    jdhao
        3
    jdhao  
       May 20, 2020 via Android
    先说需求,说不定有更好的方法
    xpresslink
        4
    xpresslink  
       May 21, 2020
    用{}本身做转义符,如果要显示{} 要写成 {{}}
    Latin
        5
    Latin  
       May 21, 2020
    alembic 用的是 mako 模版
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   756 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 22:33 · PVG 06:33 · LAX 15:33 · JFK 18:33
    ♥ Do have faith in what you're doing.