Way to Enter Multiple Values With Raw_Input UserPageVisits:632 active 80 80 DaniWeb 561 60 2015-04-25T21:51:01+00:00 https://www.daniweb.com/programming/software-development/code/495069/way-to-enter-multiple-values-with-raw-input

Way to Enter Multiple Values With Raw_Input

BustACode

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.

632 Views
About the Author

Science and Math Researcher (For Fun)

code snippet
# 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()