快速版本: 我想弄清楚如何将一个脚本中的函数的列表或元组传递给另一个脚本中的函数。我遇到的问题是,它总是在第二个脚本中变为NoneObjectType,然后除了将它打印为长字符串之外,我无法对其进行任何操作。返回Python中的特定类型
长版本: 我使用一个名为波塞尔的3D程序,它允许使用Python来自动匹配任务。正因为如此,我制作了一个名为SelectMultiple的小脚本,它给了我一个很好的wxPython窗口,我可以选择我想修改的项目。因为我一遍又一遍地看到使用它,我希望它成为它自己的脚本。
下面是函数,我从打电话的selectMultiple:
def MyApp():
title = "Select from list"
# Make the selection window pop up
mydialog = userInput(title, lst)
popupwindow = mydialog.ShowModal()
# If the user cancels win = 0
if popupwindow == wx.ID_CANCEL:
print "User canceled"
return
# Get the selected actors
selected = mydialog.GetSelectedActors()
# We are finished with the dialog
mydialog.Destroy()
return lst(selected)
默认选择是一个元组,你可以看到我试图返回之前铸造它作为一个列表,但它不” t在我的另一个剧本中表现出来。该文件不会导入,我可以打印它并获取一个显示内容的字符串,但它始终是NoneType,我不能用它做很多事情。这是我打来的脚本:
import poser
import os
scene = poser.Scene()
pathname = os.path.split(poser.AppLocation())[0]
pathname = os.path.join(pathname, 'Runtime', 'Python', 'poserScripts', 'ScriptsMenu', 'GadgetGirl')
sys.path.append(pathname)
try:
import SelectMultiple
except:
print "Could not import SelectMultiple script"
def ChoiceWindow():
title = "SuperFly Node Fixer"
message = "Choose the operation to preform"
list_of_operations = ["Delete Node", "Detach Node", "Re-Link Node"]
drop_down_window = poser.DialogSimple.AskMenu(title, message, list_of_operations)
return drop_down_window
def Controller():
script_to_run = ChoiceWindow()
#Need to call multiple so that we can know on what figures
list_of_figures = SelectMultiple.MyApp()
print type(list_of_figures)
Controller()
所以是的,我怎么得到一个非None类型的东西回来。
您是否打算偶尔输入'list(selected)'而不是'lst(selected)'?如果有意的话,你还需要展示一个'mydialog.GetSelectedActors()'的最小例子' – Dan
你是否100%确定'return lst(selected)'正在被执行?如果你的脚本进入'如果popupwindow == wx.ID_CANCEL:'conditional,那么'return'将会执行,返回值将是'None'。 – Kevin
你的意思是'lst'而不是'list'?在返回之前尝试打印出该值。听起来像这个问题是由'userInput'返回的对象。 –