gpt4 book ai didi

python - 这乱七八糟的怎么办?更好地重写它的想法?

转载 作者:行者123 更新时间:2023-11-28 20:53:33 25 4
gpt4 key购买 nike

这个烂摊子运行良好,但如果有人有任何想法让它看起来/性能更好,我们将不胜感激!

def OnButtonClick(b, e, f="none"):
if b == Gui["goleft"] and e == viz.UP: do_Cam([1.475, 7.862, 10.293])
if b == Gui["gocenter"] and e == viz.UP: do_Cam([0, 1, 52])
if b == Gui["goright"] and e == viz.UP: do_Cam([0, 11, 5])
if b == Gui["godown"] and e == viz.UP: do_Cam([0, 16, 53])

def OnSliders(POS, S):
if S == 1:
Gui["bars_alpha"].message(str('%.2f'%(POS)))
CFG["BAR_alpha"] = POS
for i in BAR_Items: BAR_Items[i].alpha(POS)
elif S == 2:
Gui["shps_alpha"].message(str('%.2f'%(POS)))
CFG["SHP_alpha"] = POS
for i in ISOS.keys(): SHAPE[i+"_SHP"].alpha(POS)
elif S == 3:
Gui["bars_sizes"].message(str('%.2f'%(POS)))
CFG["BAR_scale"] = [POS, 0.15, POS]
for i in BAR_Items: BAR_Items[i].scale(POS, BAR_Items[i].getScale()[1], POS)
elif S == 4:
Gui["label_alpha"].message(str('%.2f'%(POS)))
CFG["BARTXT_alpha"] = POS
for i in BAR_Label: BAR_Label[i].alpha(POS)
elif S == 5:
Gui["label_size"].message(str('%.2f'%(POS)))
CFG["BARTXT_scale"] = [POS, POS, POS]
for i in BAR_Label: BAR_Label[i].scale(POS, POS, POS)
elif S == 6:
Gui["grid_alpha"].message(str('%.2f'%(POS)))
CFG["grid_alpha"] = POS
[Griditema[i].alpha(POS) for i in Griditema]
[Griditemb[i].alpha(POS) for i in Griditemb]

在遵循了我收到的一些初步建议后,我现在:

def OnButtonClick(b, e, f="none"):
if e != viz.UP: return
if b == Gui["goleft"] : do_Cam([1.475, 7.862, 10.293])
elif b == Gui["gocenter"] : do_Cam([0, 1, 5])
elif b == Gui["goright"] : do_Cam([0, 1, 5])
elif b == Gui["godown"] : do_Cam([0, 1, 5])

def OnSliders(POS, S):
if S == 1:
CFG["BAR_alpha"] = POS
for i in BAR_Items: BAR_Items[i].alpha(POS)
elif S == 2:
CFG["SHP_alpha"] = POS
for i in ISOS.keys(): SHAPE[i+"_SHP"].alpha(POS)
elif S == 3:
CFG["BAR_scale"] = [POS, 0.15, POS]
for i in BAR_Items: BAR_Items[i].scale(POS, BAR_Items[i].getScale()[1], POS)
elif S == 4:
CFG["BARTXT_alpha"] = POS
for i in BAR_Label: BAR_Label[i].alpha(POS)
elif S == 5:
CFG["BARTXT_scale"] = [POS, POS, POS]
for i in BAR_Label: BAR_Label[i].scale(POS, POS, POS)
elif S == 6:
CFG["grid_alpha"] = POS
for i in Griditema: Griditema[i].alpha(POS)
for i in Griditemb: Griditemb[i].alpha(POS)

mydict = {1:"bars_alpha", 2:"shps_alpha", 3:"bars_sizes", 4:"label_alpha", 5:"label_size", 6:"grid_alpha"}
Gui[mydict[S]].message('%.2f' % POS)

结局是这样的:

def OnButtonClick(b, e, f="none"):
if e != viz.UP: return
if b == Gui["goleft"] : do_Cam([1.475, 7.862, 10.293])
elif b == Gui["gocenter"]: do_Cam([0, 1, 5])
elif b == Gui["goright"] : do_Cam([0, 1, 5])
elif b == Gui["godown"] : do_Cam([0, 1, 5])

def OnSliders(POS, S):
D = {1:"BAR_alpha", 2:"SHP_alpha", 3:"BAR_scale", 4:"TXT_alpha", 5:"TXT_scale", 6:"grid_alpha"}
if S == 1: CFG[D[S]] = POS; [BAR_Items[i].alpha(POS) for i in BAR_Items]
elif S == 2: CFG[D[S]] = POS; [SHAPE[i+"_SHP"].alpha(POS) for i in ISOS.keys()]
elif S == 3: CFG[D[S]] = [POS, 0.15, POS]; [BAR_Items[i].scale(POS, BAR_Items[i].getScale()[1], POS) for i in BAR_Items]
elif S == 4: CFG[D[S]] = POS; [BAR_Label[i].alpha(POS) for i in BAR_Label]
elif S == 5: CFG[D[S]] = [POS, POS, POS]; [BAR_Label[i].scale(POS, POS, POS) for i in BAR_Label]
elif S == 6: CFG[D[S]] = POS; [Griditema[i].alpha(POS) for i in Griditema]; [Griditemb[i].alpha(POS) for i in Griditemb]
Gui[D[S]].message('%.2f' % POS)

感谢您的帮助!

最佳答案

我会按照 Preet Sangha 的建议进行这些额外的改进。

替换

str('%.2f'%(POS))

'%.2f' % POS

我认为使用列表理解来产生副作用是一种不好的做法。

[Griditema[i].alpha(POS) for i in Griditema]

假设 Griditema 是一个字典。

for item in Griditema.itervalues():
item.alpha(POS)

关于python - 这乱七八糟的怎么办?更好地重写它的想法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4047922/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com