Call a function from another file?

前端 未结 17 2745
梦谈多话
梦谈多话 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 09:09

    First of all you do not need a .py.

    If you have a file a.py and inside you have some functions:

    def b():
      # Something
      return 1
    
    def c():
      # Something
      return 2
    

    And you want to import them in z.py you have to write

    from a import b, c
    

提交回复
热议问题