Closed JeroenSchmidt closed 4 years ago
Is it possible to write a function that generates a list of choices that takes in more then one argument (other then
answers
)?I want to do somthing like this:
from PyInquirer import prompt def generate_list(answers, arg2): return([x for x in range(0,arg2)]) def main(): arg2=10 questions = [ { "type":"list", "name":"tables", "message":"Which tables would you like to map?", "choices":generate_list(answer,arg2) } ] answers = prompt(questions )
there are two ways.
from functools import partial
def generate_list(answers, arg2):
return([x for x in range(0,arg2)])
def main():
arg2=10
questions = [
{
"type":"list",
"name":"tables",
"message":"Which tables would you like to map?",
"choices": lambda x: generate_list(x, arg2=arg2)
}
]
answers = prompt(questions )
or using from functools import partial
from functools import partial
def generate_list(answers, arg2):
return([x for x in range(0,arg2)])
def main():
arg2=10
_generate_list = partial(generate_list, arg2=arg2)
questions = [
{
"type":"list",
"name":"tables",
"message":"Which tables would you like to map?",
"choices":_generate_list
}
]
answers = prompt(questions )
@rafarui Thanks a lot, that's exactly what I needed.
I can see this is settled, I will be closing this
Is it possible to write a function that generates a list of choices that takes in more then one argument (other then
answers
)?I want to do somthing like this: