'''python
from T123_P2_func import add_books
def print_menu(commandmenu:dict)-> list:
menu_options = {
1: 'Command Line L)oad file',
2: 'Command Line A)dd book',
3: 'Command Line R)emove book',
4: 'Command Line F)ind book by title',
5: 'Command Line NC) Number of books in a category',
6: 'Command Line CA) Categories for an author',
7: 'Command Line CB) Categories for a book title',
8:'Command Line G)et book''\n'
'R)ate A)uthor P)ubliosher C)ategory',
}
for key in menu_options.keys(): print(key, '-', menu_options[key] ) print_menu(menu_options)
File = None
while True: userinput = (input('Please enter a Command: '))
userinput = userinput.upper()
if userinput == 'L':
print('Book has been Loaded.')
file = books_to_list('')
elif userinput == 'A':
print('Book has been Added.')
elif userinput == 'R':
print('Book has been Removed.')
elif userinput == 'F':
print('Book has been Found.')
print(userinput)
word1 = (input('Press Q to Quit: '))
if word1 == 'Q':
break
'''
When I call the function from another file every function in that file runs, please what could be the problem and what do I do if I want to call this function by pressing a Letter ?
CodePudding user response:
Do you mean that every function from practicing.py
runs, or that the code in the main part of practicing.py
runs when you import the module?
If everything in the external module is wrapped inside function definitions, importing the module shouldn't have any effect on what you're doing in the main program.
If you still want code that is in the main part of the external module to be executable by running that file, the thing to do is wrap the main part of the module in a function def main():
and put the following in the main part of the module (this will not run if the module is imported, only if it is run directly):
if __name__ == "__main__":
main()
CodePudding user response:
I can't see entire of code.
But, I think you have to know how to utilize the argument of the function.