使用Python编写MakeHuman文件:无效的语法错误

时间:2017-02-06 23:23:11

标签: python syntax-error makehuman

我的语法错误无效,空格在星号

处突出显示
"* modifier macrodetails/Caucasian ' + str(CaucasianQuotient) + '\n\"

我多次经历了整个事情,但我仍然不知道出了什么问题

ListOfBodyShape = ['Round', 'RoundBottom', 'RoundTop', 'RoundMuscular', 'MuscularBottom', 'MuscularTop', 'Muscular', 'TopBottom']
ListOfHeight = ['Medium', 'MediumShort', 'TallMedium', 'TallShort', 'Tall', 'Short']
ListOfHairStyle = ['Short', 'Long', 'CurlyShort', 'CurlyLong']
Gender = ['Male', 'Female']
ListOfAges = ['Child', 'Teen', 'Adult', 'Elder']

MuscleQuotient = 0
AfricanQuotient = 0
ProportionQuotient = 0
GenderQuotientQuotient = 0
HeightQuotient = 0
BreastSizeQuotient = 0
AgeQuotient = 0
BreastFirmnessQuotient = 0
AsianQuotient = 0
CaucasianQuotient = 0
WeightQuotient = 0

for a in range(len(ListOfBodyShape)):
    for b in range(len(ListOfHeight)):
        for c in range(len(ListOfHairStyle)):
            for d in range(len(Gender)):
                for e in range(len(ListOfAges)):
                    f = open(ListOfBodyShape[a] + ' ' + ListOfHeight[b] + ' ' + ListOfHairStyle[c] + ' ' + Gender[d] + ' ' + ListOfAges[e]  + '.mhm', 'w')

                    f.write('version v1.1.0\n\
                    tags untitled\n\
                    camera 6.0 347.5 -0.113847193662 0.694580827356 -0.399507358182 0.6375\n\
                    modifier macrodetails-universal/Muscle ' + str(MuscleQuotient) + '\n\
                    modifier macrodetails/African ' + str(AfricanQuotient) + '\n\
                    modifier macrodetails-proportions/BodyProportions '+ str(ProportionQuotient) +'\n\
                    modifier macrodetails/Gender ' str(GenderQuotient) + '\n\
                    modifier macrodetails-height/Height ' + str(HeightQuotient) + '\n\
                    modifier breast/BreastSize' + str(BreastSizeQuotient) + '\n\
                    modifier macrodetails/Age ' + str(AgeQuotient) + '\n\
                    modifier breast/BreastFirmness ' + str(BreastFirmnessQuotient) + '\n\
                    modifier macrodetails/Asian ' + str(AsianQuotient) + '\n\
                    modifier macrodetails/Caucasian ' + str(CaucasianQuotient) + '\n\
                    modifier macrodetails-universal/Weight ' + str(WeightQuotient) + '\n\
                    eyes HighPolyEyes 2c12f43b-1303-432c-b7ce-d78346baf2e6\n\
                    clothesHideFaces True\n\
                    skinMaterial skins/default.mhmat\n\
                    material HighPolyEyes 2c12f43b-1303-432c-b7ce-d78346baf2e6 eyes/materials/brown.mhmat\n\
                    subdivide False\n')

2 个答案:

答案 0 :(得分:2)

A" +"在此行的str之前缺少符号:

'modifier macrodetails/Gender ' str(GenderQuotient) + '\n\ "

最后也使用f.close()。

答案 1 :(得分:1)

首先,您应该了解您的循环中不需要范围。

for a in range(len(ListOfBodyShape)): # a range
    x = ListOfBodyShape[a]  # get value with index

完全相同
for x in ListOfBodyShape:  # get value

旁注:Python命名约定不是用大写字母开始变量

我建议不要写一大块文字。

我不知道你的输出需要什么,但是Python有多行字符串,所以除非你需要,否则你不应该自己编写\n

另外,\n\不仅仅是一个新行。

首先从这个

开始
f.write("""version v1.1.0
tags untitled
camera 6.0 347.5 -0.113847193662 0.694580827356 -0.399507358182 0.6375\n""")

然后我会建议你使用字符串格式。

f.write("modifier macrodetails-universal/Muscle {}\n".format(MuscleQuotient))

不要忘记使用f.close()

或者你可以这样做

filename = "{} {} {} {} {}.mhm".format(ListOfBodyShape[a], ListOfHeight[b], ListOfHairStyle[c], Gender[d], ListOfAges[e])
with open(filename), 'w') as f:
    f.write(...)
# f.close() automatically