Python中用format函数格式化字符串的用法

今天看这个cmd='../bin/SMILExtract -C ../config/{0} -I {1} {2} {3}/{4}' 命令感觉很奇怪

原来是字符串拼接

# encoding:UTF-8

importglob

importos

importsubprocess

fromsettingimport*

'''

- 批处理, 低/高阶特征提取,输出为arff文件格式, 修改了conf文件后保存为libsvm输出

'''

# 从音频文件中提取高阶特征

deffeatureExtract(audioRoot,outdir,cmd,fconfig,outflag,output_postfix):

foriteminglob.iglob(audioRoot):

# print(item)

_, audioname=os.path.split(item)

filestr, postfix=os.path.splitext(audioname)

# 提取文件名

# print(filestr)

[label, name]=filestr.split('-',1)

# print('----original label:%s' % label)

ifint(label)>0:

label=1

# print(str(label))

featurename=filestr+output_postfix

command=cmd.format(fconfig, item, outputflag, featureDir,

featurename)# \\ is must in MacOS env, but clear in other env

# print(command)

# subprocess.call(command, shell=True, stdout=FNULL, stderr=subprocess.STDOUT)

subprocess.call(command,shell=True)# with debug information

if__name__=='__main__':

os.chdir(DATAROOT)

audioRoot='audio/*.wav'

featureDir='../features/csv'

/Users/fwei/pingan/audioExtract/dataset/config/{0} -I {1} {2} {3}/{4}'

cmd='../bin/SMILExtract -C ../config/{0} -I {1} {2} {3}/{4}'

fconfig='emobase_csv.conf'

outputflag='-O'

featurename='.csv'

featureExtract(audioRoot, featureDir, cmd, fconfig, outputflag, featurename)

# for item in glob.iglob(audioRoot, recursive=True):

#    # print(item)

#    _, audioname = os.path.split(item)

#    filestr, postfix = os.path.splitext(audioname)

#    # 提取文件名

#    # print(filestr)

#    [label, name] = filestr.split('-', 1)

#    # print('----original label:%s' % label)

#    if int(label) > 0:

#        label = 1

#    # print(str(label))

#

#    # featurename = filestr + output_postfix

#    featurename = 'output.lsvm'

#    command = cmd2.format(fconfig, item, outputflag, featureDir, featurename) + ' -classes \\{0,1\\} -classlabel ' + str(label)    # \\ is must in MacOS env, but clear in other env

#    # print(command)

#    # subprocess.call(command, shell=True, stdout=FNULL, stderr=subprocess.STDOUT)

#    subprocess.call(command, shell=True)          # with debug information

你可能感兴趣的:(Python中用format函数格式化字符串的用法)