Way to Enter Multiple Values With Raw_Input

BustACode 1 Tallied Votes 696 Views Share

Allows multiple entries using raw_input.

I often have to enter multiple items in my Python programs. I desired an easier way than using a loop(s). Today I discovered a way, and with a few mods made it happen.

# References:  https://stackoverflow.com/questions/11664443/raw-input-across-multiple-lines-in-python
# Main #
def main():
        # Main Code
# Default DEBUG Print Option

    v_List = []
    v_Stop = "" # Defines the iter()'s sentinel which stops the inter() when this string is seen
    for i in iter(lambda: raw_input("Enter a value or [ENTER] to end: "), v_Stop): ## Using "lambda" bypasses need for "raw_input" to be "callable."
        print("{}".format(i)) ## Use if wish to view values as entered.
        v_List.append(str(i)) ## All entries in Str type unless changed to Int().
    print(v_List)

    # Main Loop #
if __name__ == '__main__':
    main()