[Tutor] what's wrong with this ?

Danny Yoo danny.yoo at gmail.com
Tue Apr 21 09:50:14 CEST 2015


On Apr 21, 2015 12:27 AM, "lei yang" <yanglei.fage at gmail.com> wrote:
>
> >>>start_time = "2014-7-1"
> >>> revlines = commands.getoutput("git log --pretty=format:'%ad:%an'
> --date=short --since='%s' --no-merges" %start_time).strip().split('\n')
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> ValueError: unsupported format character 'a' (0x61) at index 26

Your format string has an embedded format string in it.  Although you may
think it obvious that Python should know not to touch the embedded format
string since there are single quotes, Python doesn't take those single
quote characters with any reverence.  Therefore, it can't tell that you
want to keep the embedded one as a literal.

Fundamentally, building a command string with string formatting is error
prone: consider the subprocess module and passing an explicit list of
arguments, rather than a single string.


More information about the Tutor mailing list