raw input - Limiting raw_input in python -
how can limit amount of characters user able type raw_input
? there easy solution problem, can't figure out.
a simple solution adding significant message , using slicing first 40 characters:
some_var = raw_input("input (no longer 40 characters): ")[:40]
another check if input length valid or not:
some_var = raw_input("input (no longer 40 characters): ") if len(some_var) < 40: # ...
which should choose? depends in implementation, if want accept input "truncate" it, use first approach. if want validate first (if input has correct length) use second approach.
Comments
Post a Comment