CITGuru / PyInquirer

A Python module for common interactive command line user interfaces
MIT License
1.91k stars 236 forks source link

Using a seperate list for choices? #69

Open Sentr1k opened 4 years ago

Sentr1k commented 4 years ago

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 } ]

Shinyhero36 commented 4 years ago

@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