473,224 Members | 1,596 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,224 software developers and data experts.

Providing Default Value for User Input

I have just begun learning Python so that I can write a simple script
to make modification of a file used by another Python script easier.
This file is basically a list of regular expressions. What I want to
do is allow the user to select one of these regular expressions to
modify, but I've realized I know of no way to provide a default value
for user input. I could choose to show the regular expression the user
has chosen and simply allow the user to retype it and modify it from
there, but that is time consuming and error prone. Does Python support
a way to do this? If worse comes to worst, is there a way I could
write such code on my own without having to write a C-based module
(I'd like to stick to Python code only since some users will be
running this script on Windows without a C compiler)?
Jul 18 '05 #1
3 3408
N?ant Humain wrote in message ...
I have just begun learning Python so that I can write a simple script
to make modification of a file used by another Python script easier.
This file is basically a list of regular expressions. What I want to
do is allow the user to select one of these regular expressions to
modify, but I've realized I know of no way to provide a default value
for user input. I could choose to show the regular expression the user
has chosen and simply allow the user to retype it and modify it from
there, but that is time consuming and error prone. Does Python support
a way to do this? If worse comes to worst, is there a way I could
write such code on my own without having to write a C-based module
(I'd like to stick to Python code only since some users will be
running this script on Windows without a C compiler)?


This question is entirely too vague, because the answer depends entirely
upon your implementation and has nothing to do with Python per se. I
imagine the answer is pretty simple unless your design is horrible.

As a shot in the dark, why not just look at what the user types? If it's
something you want to interpret as 'use default' (like just an empty line,
or the letter 'd' or something), then use a default!

E.g.:

choices = dict(a=1, b=2, default=100)
while True:
print 'Please select:'
for k,v in choices.items():
print '%-10s%s' % (k,v)
input = raw_input('?> ').lower()
if input == 'd':
input = 'default'
try:
print 'Value of %s is %s' % (input, choices[input])
except KeyError:
print 'Item %r not found.' % input
print
If you're doing a lot of command-oriented input loops, look at the cmd
module, which is pretty handy (I use it quite a bit).
--
Francis Avila
Jul 18 '05 #2
Hello,
I have just begun learning Python so that I can write a simple script
to make modification of a file used by another Python script easier.
This file is basically a list of regular expressions. What I want to
do is allow the user to select one of these regular expressions to
modify, but I've realized I know of no way to provide a default value
for user input. Which user input? raw_input, Tkinter, wxPython ...
I could choose to show the regular expression the user
has chosen and simply allow the user to retype it and modify it from
there, but that is time consuming and error prone. Does Python support
a way to do this? To do what? I don't understand your question. Maybe an example will
help.
If worse comes to worst, is there a way I could
write such code on my own without having to write a C-based module
(I'd like to stick to Python code only since some users will be
running this script on Windows without a C compiler)?

If you create a C extension you can distribute just the binary so your
users won't need a C compiler. (They might need some required DLL's
but you can ship them as well).

HTH.
Miki
Jul 18 '05 #3
Francis Avila wrote in message <10*************@corp.supernews.com>...
This question is entirely too vague, because the answer depends entirely
upon your implementation and has nothing to do with Python per se. ....
As a shot in the dark, why not just look at what the user types? If it's


As Miki showed me, even is saying the question is too vague, I *already*
assumed too much in my answer to you, namely, that you were using a CLI. I
don't even know that.

So you see the problem with your question? We're glad to help, but you need
to give us more specific information.
--
Francis Avila

Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Sarah West | last post by:
Hi, I have the following problem; This is my form, i would like to default the select box to USA, and default the text field to a name such as 'Sarah' and the hidden field to another number...
3
by: James Bond 007 | last post by:
Given the following example, I want "Jane Doe" to appear when the user first views the form, and when he leaves it blank: // ---------------- <FORM .... > Name: <INPUT TYPE="text"...
11
by: BerkshireGuy | last post by:
Hello, I need to create an interactive report that can be sent to agencies with the following: Application #, Date Approved, Reason Not Taken The reason not take should be a drop down in...
21
by: planetthoughtful | last post by:
Hi All, As always, my posts come with a 'Warning: Newbie lies ahead!' disclaimer... I'm wondering if it's possible, using raw_input(), to provide a 'default' value with the prompt? I would...
5
by: HandersonVA | last post by:
should I set to "0" as a default value on a quantity and a price field or set to "null"? if a user enter nothing on the quantity or price field on a web browser, should I treat it as null or "0"?...
8
by: hanseymoon | last post by:
How do you create a text input box, which shows a default value of 1+ and blocks the user from deleting it? Thanks so much! :))
12
by: Doogie | last post by:
How do I make a value the default value for a combo box in ASP 3.0? What I have below does NOT work, yet I've seen it in HTML file examples before (and works if I put it in a HTML file by itself,...
2
by: Etienne Hilson | last post by:
Hello the list :-) I do a little program that permit the user to manage list of sentences. This program runs into a linux shell. The user can add, modify and delete the sentences. What I want...
2
by: windandwaves | last post by:
Hi Folk For input boxes in forms, some forms have default values e.g. "enter phone number here". When a user wants to enter their details, they first have to remove the default entry - which...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.