PyInquirer icon indicating copy to clipboard operation
PyInquirer copied to clipboard

Using a seperate list for choices?

Open Sentr1k opened this issue 5 years ago • 1 comments

Say I have a list that's user created, or I'm storing options for restoring save points in my program, I need keys that can be displayed.

Something like: list = [Key1, Key2 ,Key3 ,Key4 ,Key5] questions = [ { 'type': 'list', 'name': 'saves', 'message': "What save would you like to load?", 'choices': list } ]

Sentr1k avatar Jul 13 '19 06:07 Sentr1k

@Sentr1k I finally found how to do it here is the question/answer


questions = [
		{
		'type': 'list',
		'name': 'file',
		'message': 'Select file to open',
		'choices': list_files(projects_path),
		}
		]
answers = prompt(questions, style=custom_style_2)

and here is my function with parameter

def list_files(projects_path):
	files = []
	for file in listdir(str(projects_path)):
		files.append(file)
	return files

Here is the result: image

@CITGuru you can close this issue now

gerald-lbn avatar Jul 19 '19 10:07 gerald-lbn