Newbie question

Joal Heagney s713221 at student.gu.edu.au
Fri Sep 21 22:31:22 EDT 2001


> "Horváth Árpád" <ahorvath at ns.szgti.kando.hu> wrote in message
> news:6a6bf63.0109190727.2dee936 at posting.google.com...
> > Dear Python Programmers,
> >
> > how can I get information from the keyboard like with raw_input, but
> > with a default value, what I can edit.
> >
> > For example:
> >
> > When: 23 Sept 2001.
> >
> > I want the computer to write the actual date, and I can edit it.
> >
> >    Arpad

If you really want to use raw_input, you could do the following:

>>> def getvalue(default):
...     inp = raw_input("""Enter value here, defaults to "%s": """ %
default)
...     if inp == "":
...             return default
...     else:
...             return inp
...
>>> getvalue('hello')
Enter value here, defaults to "hello":
'hello'
>>> getvalue('spam')
Enter value here, defaults to "spam": I don't like spam
"I don't like spam"
>>>
-- 
      Joal Heagney is: _____           _____
   /\ _     __   __ _    |     | _  ___  |
  /__\|\  ||   ||__ |\  || |___|/_\|___] |
 /    \ \_||__ ||___| \_|! |   |   \   \ !



More information about the Python-list mailing list