Python (Softimage input box) and function arguments -
i'm new programming (about week old). i've run little problem in python, couldn't find helpful in searches (new here well).
the script made below working if don't use softimage's inputbox
l1 = ['taskmaster', 'red skull', 'zemo'] l2 = ['capt. america', 'iron man', 'thor'] def findguy (where, inputguy): = "not here" in (range(len(where))): if where[i] == inputguy: = "yes here" print #findguy (l1, 'taskmaster') x = application.xsiinputbox ("who looking for?","find character") y = application.xsiinputbox ('which list?','search list') findguy (y, x)
if use findguy(type inputs here directly) code works, if try input through input box in softimage keeps returning "not here"
if kind enough week old struggling self learner, appreciated.
thanks, gogo
your method works fine. problem lies in fact input from
y = application.xsiinputbox ('which list?','search list')
will string. y
string , not list. same applies x
of course doesn't give issue because lists contain strings.
what happens function call looks (example)
findguy('l1', 'zemo')
and on line
if where[i] == inputguy:
it compare characters of l1
, being l
, 1
inputguy
. of course keeps being false "not here" output.
what want function call instead
findguy(l1, 'zemo')
this can achieved doing this:
y = application.xsiinputbox ('which list?','search list') if y == "l1": y = l1 elif y == "l2": y = l2
this 'picks' list based on input , passes findguy
. in situation o.k. solution if code example , actual code has more lists, or have in future should better solution. suggestion store guys in dictionary instead:
guys = {'l1': ['taskmaster', 'red skull', 'zemo'], 'l2': ['capt. america', 'iron man', 'thor']}
then can process input
x = application.xsiinputbox ("who looking for?","find character") y = application.xsiinputbox ('which list?','search list') findguy (guys[y], x)
this works because dictionary's keys strings.
Comments
Post a Comment