Call a function from another file?

前端 未结 17 2422
梦谈多话
梦谈多话 2020-11-22 08:06

Set_up: I have a .py file for each function I need to use in a program.

In this program, I need to call the function from the external files.

I\'ve tried:

17条回答
  •  悲&欢浪女
    2020-11-22 08:49

    You can do this in 2 ways. First is just to import the specific function you want from file.py. To do this use

    from file import function
    

    Another way is to import the entire file

    import file as fl
    

    Then you can call any function inside file.py using

    fl.function(a,b)
    

提交回复
热议问题