What is the equivalent in python to this code line in perl $conf{svnlook} log --revision $rev $repo
What is the equivalent in python to this code line in perl
$conf{svnlook} log --revision $rev $repo
i'm lo开发者_如何学编程oking in python for something as neat as that...
That's not really valid Perl. Are you sure it wasn't something like this?
my $log = `$conf{svnlook} log --revision $rev $repo`;
That's calling the svnlook program, an external program not part of Perl. You can do the same thing in Python.
To be exact, what you have there is not a perl command, that is a formatted string... I am assuming you are sending a string command to the shell... to do so in python you can do this...
# assign conf as a dict()
# assign rev and repo as variables
import os
os.system('%s log --revision %s %s' % (conf['svnlook'], rev, repo))
EDIT To answer your question about string formatting, there are python template strings and python format strings... I will demonstrate format strings in the python shell...
>>> 'Coordinates: {latitude}, {longitude}'.format(latitude='37.24N', longitude='-115.81W')
'Coordinates: 37.24N, -115.81W'
>>>
However, this is still more verbose than perl
from subprocess import call
call([conf['svnlook'], 'log', '--revision', rev, repo])
精彩评论