I was trying to make it so that if you input the name (lets say it is Frank) I wouldn't really want to have to open the program in IDLE and have to edit the entire thing again just to add in Frank.
A lot of people use some sort of configuration file, typically as ~/.namerc
(or ./.namerc
) to store your preferences.
Reading a JSON File
If you want an example of getting a json file from a user's current directory, see this answer.
You'll need a json file, you'll want to include an area for what username to search for.
test.json
{
"name": "Frank"
}
yourDatabaseScript.py
import json
with open("test.json") as json_file:
json_data = json.load(json_file)
print(json_data["name"])
On the command line
$> python ./yourDatabaseScript.py
Frank
Many times it's used to minimize the number of command line arguments, which are another popular way of getting input from a user without using input
.
Reading from the Command Line
I prefer the vanilla python docs when reading up on it.
yourDatabaseScript.py
import argparse
parser = argparse.ArgumentParser(description='Get a name for a search.')
parser.add_argument('--name', dest='input', action='store_const',
const=str,
help='Enter a user\'s name to search')
args = parser.parse_args()
print args.input # Frank
On the command line
$> python ./yourDatabaseScript.py --name="Not Frank"
Not Frank
$> python ./yourDatabaseScript.py --name Frank
Frank
On a side note
name = input("What is your name?")
if input == name:
print(final % (name, fav_color, weight, height))
input
is a function that you've called on line one. You are checking that the value of calling input
is the same thing as itself. I think this is a typo.