简体   繁体   中英

I'm having a problem calling a function from a different file

from practicing import sort_books_publisher
sort_books_publisher()

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?

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()

I can't see entire of code.

But, I think you have to know how to utilize the argument of the function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM