擅长:python、mysql、java
<p>看起来<a href="https://github.com/asottile/pyupgrade" rel="nofollow noreferrer">pyupgrade</a>既能将<code>%</code>格式转换为<code>format</code>调用,又能将<code>format</code>调用转换为f字符串</p>
<blockquote>
<h1>printf-style string formatting</h1>
<p>Availability:</p>
<p>Unless <code> keep-percent-format</code> is passed.</p>
<pre><code>'%s %s' % (a, b) # '{} {}'.format(a, b)
'%r %2f' % (a, b) # '{!r} {:2f}'.format(a, b)
'%(a)s %(b)s' % {'a': 1, 'b': 2} # '{a} {b}'.format(a=1, b=2)
</code></pre>
</blockquote>
<hr/>
<blockquote>
<h1>f-strings</h1>
<p>Availability:</p>
<p><code> py36-plus</code> is passed on the commandline.</p>
<pre><code>'{foo} {bar}'.format(foo=foo, bar=bar) # f'{foo} {bar}'
'{} {}'.format(foo, bar) # f'{foo} {bar}'
'{} {}'.format(foo.bar, baz.womp} # f'{foo.bar} {baz.womp}'
</code></pre>
</blockquote>
<p>注意:pyupgrade是故意的,如果它会使表达式变长,或者如果替换参数不是简单名称或虚线名称(因为这会降低可读性),则不会创建f字符串。在</p>