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)? 3 3437
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
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
Francis Avila wrote in message <10************ *@corp.supernew s.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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 like '876543', when the user clicks on the check box, otherwise the
fields should be blank, the value of the select box dosnt matter much, only
that it defaults to USA, when the user checks it. Can anyone help? i have
tried a google with no luck,...
|
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" NAME="user_name" VALUE="Jane Doe"
SIZE="25" MAXLENGTH="30" REQUIRED="YES">
// ----------------
|
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 which the agency can
select as to why the application wasnt approved and then send the
"report" back to us.
|
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 like to include the ability to edit an existing value (drawn
from an SQLite table) using a DOS console Python app, but my gut
|
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"? I am so confused about this
concept. please advise me. thank you.
| |
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! :))
|
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, but
not if I use it in a ASP 3.0 app.
<select name="cboCompany" style="text-align:right; font-size:8pt">
<option value="08">08</option>
<option value="09" selected="true">09</option>
<option value="33">33</option>
|
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 to do is :
When the user want to modify one sentence, I would like to do this :
|
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 can be a bit annoying
at times. I have written a very simple little script (obviously not
the first one) that removes the default entry. You can find it here:
http://www.sunnysideup.co.nz/j/form/
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |