I'm completely new to python, I just started about 3 days ago. I've requested some books from my library on python, so I hope I'm headed in the right direction. I hate to ask this because I'm sure it's been asked before, but I don't know what it is called so I don't even know where to begin. Is it possible to edit the code of a python program, while executing it. -
if loop == 2:
-
def menu(list,question):
-
for entry in list:
-
print 1+list.index(entry),
-
print ") " + entry
-
-
return input (question) - 1
-
-
CEF = ['CURRENT OBJECTIVES','CURRENT TARGET','CURRENT MISSION','Exit']
-
-
name = raw_input("Please insert your name: ")
-
print "Hello", name,"Welcome to the Information Desk"
-
print ""
-
while loop == 2:
-
choice = menu(CEF, "Please Select: ")
-
if choice == 0:
-
Print "There is no information"
-
if choice == 1:
-
print "There is no information"
-
if choice == 2:
-
print "There is no information"
-
if choice == 3:
-
print "Thank You",name
-
sleep(2)
-
loop = 4
-
I want to change the places where it says "there is no information" to whatever I want, without having to edit the code manually, instead I would like to enter the information with the program itself. Almost like changing the value of a variable, except, making it permanent, so it will be like that next time I run the program.
Again, sorry if this has already been asked, but What is this called and How do I do it?
7 1571 - if loop == 2:
-
def menu(list,question):
-
for entry in list:
-
print 1+list.index(entry),
-
print ") " + entry
-
-
return input (question) - 1
-
-
CEF = ['CURRENT OBJECTIVES','CURRENT TARGET','CURRENT MISSION','Exit']
-
-
name = raw_input("Please insert your name: ")
-
print "Hello", name,"Welcome to the Information Desk"
-
print ""
-
while loop == 2:
-
choice = menu(CEF, "Please Select: ")
-
if choice == 0:
-
Print "There is no information"
-
if choice == 1:
-
print "There is no information"
-
if choice == 2:
-
print "There is no information"
-
if choice == 3:
-
print "Thank You",name
-
sleep(2)
-
loop = 4
A possibility would be to initialize variables before your while loop. Let's say:
choice0 = choice1 = choice2 = choice3 = 'There is no information'
Then during the loop you simply put print choice0 or print choice1...
During the loop Then you could store some kind of input with:
usr_input = raw_input('Enter some text: ')
Then you could assign one of your choices to the same value like
choice0 = usr_input
This might be what you're looking for. There's not really any specific name for this, it's just dynamic variables.
That's not exactly what I was wondering how to do. Let me rephrase:
Lets say I have a variable: a
in the code it would be written:
a = 0
When I run the code: print a
The output would be: 0
When running the program, I tell it: a = 1
in the code it would now be written:
a = 1
The actually code has changed.
How would I do this, if it is possible.
hope this makes sense.
You want it to remain as "a = 1" inside the actual code, so if you were to open it in Notepad, you would see "a = 1"?
Yes. Exactly...is that possible?
You could open the .py file, scan it, find the variable and then replace the value with some simple string manipulation.
how do you scan for the variables?
how do you scan for the variables?
You would have to write your own utility for parsing the file, but it would probably be something like this: -
f = open( my_prog.py, 'r' )
-
-
for line in f:
-
data = line.split('=')
-
if len( data ) == 2:
-
var_name = data[0]
-
try:
-
var_val = int( data[1] )
-
# Now you can change the value to whatever you want
-
except:
-
# Either a non-integer value or a string
-
pass
Simple file reading/writing and basic text parsing is all it is.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: mike420 |
last post by:
In the context of LATEX, some Pythonista asked what the big
successes of Lisp were. I think there were at least three *big*
successes.
a. orbitz.com web site uses Lisp for algorithms, etc.
b....
|
by: Sam |
last post by:
Hi I'm learning to code with C++ and wrote some very simple code. I
think it's consistent with every rule but always got compiling errors
that I don't understand.
The code include 5 files as...
|
by: G Patel |
last post by:
Hi,
If I want to call functions that don't return int without declaring
them, will there be any harm?
I only want to assign the function(return value) to the type that it
returns, so I don't...
|
by: Leon |
last post by:
Why this code is not working? I think the problem is in the business class
code.when I select a state from the dropdownlist, the school dropdownlist
suppose
to fill with school names, but somehow...
|
by: Erik Johnson |
last post by:
Maybe I just don't know the right special function, but what I am wanting to
do is write something akin to a __getattr__ function so that when you try to
call an object method that doesn't exist,...
|
by: Dougan |
last post by:
I've seen code that allocates an object on the stack and then saves a
class reference to it.
example:
void ScribbleArea::resizeImage( const QSize &newSize)
{
QImage newImage( newSize, );...
|
by: jehugaleahsa |
last post by:
Hello:
I had an hour-long discussion with my boss today. Last night, right
before I dozed off, I realized some of his code resulted in duplicate
processing. I tried to explain it to him and he...
|
by: Tem |
last post by:
I've read every example i could find on the subject and still couldn't
figure out its proper usage.
What's the point of delegates, why can't I just invoke the method
directly???
Can someone...
|
by: Nepomuk |
last post by:
You might have heard about Linux, but you don't know what it is? Or you know a few things about it, but they terrify you? Well, then this article is for you. Don't be afraid - Everyone can use Linux!...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
|
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,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
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...
| |