I'm working on a command-prompt like program in python, where the user types a command in, a dictionary finds the correlating method, and then accesses another file with all the methods in there, and then runs the one the user asked.
However, when I try to run any of them, it first print out anything besides the 'return' statement, from all the methods and then executes the method asked.
This is the main file which I run. (rcmd.py)
from commands import *
def get_input():
user = input("Guppy\RACHEAL> ")
return user
def command_line():
# LOOP DETERMINATION VARIABLE
exit = False
while exit == False:
user_input = get_input()
if user_input == "exit":
exit = True
break
elif user_input == "":
get_input()
else:
e = commands.execute(user_input)
print("FINISHED --> " + str(e))
# PROGRAM START LOOP
#
#
command_line()
This is the file where the dictionary is used to execute a method (commands.py)
from modules import *
class commands(object):
def execute(user_input):
# DICTIONARY OF COMMANDS
COMMANDS = {
# || GENERAL || #
"help" : modules.help(),
# || FIND || #
"find- time" : modules.find_time(user),
"find- date" : modules.find_date(),
# || INPUT || #
"input- log: new" : modules.input_new_log()
}
try:
execution = COMMANDS[user_input]
return execution
except KeyError:
return "ERROR --> No such command"
This is the file with all the methods import datetime
class modules(object):
# -- || GENERAL MODULES || --- #
def help():
return "Action terms:\n'find'\n'input'" + "\n__________\n"
# --- || 'FIND' MODULES || --- #
def find_time():
print("Nothing")
return datetime.datetime.now().time()
def find_date():
return datetime.datetime.now().date()
# --- || 'INPUT' MODULES || --- #
def input_new_log():
new_user_log = input("> ")
path = 'C:\\Users\\Guppy\\Projects\\RACHEAL\\RACHEALs Databases\\user_log.txt'
with open(path, 'w') as log:
log.write(new_user_log)
input_new_log_exit_code = 1
return "EXIT CODE = " + str(input_new_log_exit_code)
This is the output I get
Guppy\RACHEAL> find- date
Guppy\RACHEAL> Nothing
>
FINISHED --> 2017-31-12
Where I should just be getting
Guppy\RACHEAL> find- date
FINISHED --> 2017-31-12
If anyone has any idea why this isn't working correctly, or what I'm doing wrong, it would be really appreciated.