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

Popular posts from this blog

Change the color of an oval at click in Java AWT -

c# - Unity IoC Lifetime per HttpRequest for UserStore -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -