我有一个无效的语法错误,空格在星号处突出显示
"* 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.0n
tags untitledn
camera 6.0 347.5 -0.113847193662 0.694580827356 -0.399507358182 0.6375n
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-d78346baf2e6n
clothesHideFaces Truen
skinMaterial skins/default.mhmatn
material HighPolyEyes 2c12f43b-1303-432c-b7ce-d78346baf2e6 eyes/materials/brown.mhmatn
subdivide Falsen')
此行中的 str 之前缺少"+"符号:
'modifier macrodetails/Gender ' str(GenderQuotient) + 'n "
还要在末尾使用 f.close((。
首先,您应该了解循环中不需要范围。
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.6375n""")
然后我建议您使用字符串格式。
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