在看celery的时候,发现里面有这么一句

print('Request: {0!r}'.format(self.request))

关于里面的{0!r}是什么意思翻了一下文档。

文档里是这么描述的

replacement_field ::=  "{" [field_name] ["!" conversion] [":" format_spec] "}"

------

Two conversion flags are currently supported: '!s' which calls str() on the value, and '!r' which calls repr().

Some examples:

"Harold's a clever {0!s}"        # Calls str() on the argument first
"Bring out the holy {name!r}" # Calls repr() on the argument first

是说感叹号后面跟的是conversion,而conversion有两个值.

分别是s对应str()函数, r对应repr()函数。

因此上面的翻译一下类似于下面

"Harold's a clever {0!s}" == "Harold's a clever str({0})"

"Bring out the holy {name!r}" == "Bring out the holy repr({name})"

实际调用时的写法应该是

"Harold's a clever {0!s}".format(string) == "Harold's a clever {0}".format(str(string))

"Bring out the holy {name!r}".format(string) == "Bring out the holy {name}".format(repr(string))

最新文章

  1. Dao跨事务调用实现转账功能
  2. Maven学习-目录结构
  3. Java产生随机数
  4. android图像与图像处理系列(一、Bitmap和BitmapFactory)
  5. 查询各个商品分类中各有多少商品的SQL语句
  6. C语言之实现控制台光标随意移动
  7. 共享内存shared pool (4):Library cache 转储文件
  8. nginx笔记---http配置
  9. android78 Fragment和Activity 传递数据
  10. 在javaweb中通过servlet类和普通类读取资源文件
  11. LINUX进程上锁查看方法
  12. hdu 1564 Play a game(博弈找规律)
  13. calss 类
  14. rsa加密解密, 非对称加密
  15. Servlet基本_セッション属性
  16. jquery实现元素高度变化页面变化
  17. [Windows Azure] Using the Graph API to Query Windows Azure AD
  18. 多媒体文件格式之RMVB
  19. WPF学习笔记-用Expression Design制作矢量图然后导出为XAML
  20. MySql 模糊查询、范围查询

热门文章

  1. JS利用HTML5的Web Worker实现多线程
  2. k sum 问题系列
  3. 一个高级PHP工程师所应该具备的(转自元如枫博客)
  4. Nginx禁止使用ip访问,只允许使用域名访问
  5. Linux 命令中 find 和 xargs 命令的用法
  6. 「JSOI2011」棒棒糖
  7. ios中时间倒计时
  8. SpringBoot与Lombok
  9. Python 正则表达式之 sub 和 subn函数的使用
  10. Java中对于ClassLoader类加载器 嵌套了深度技术的价值