Call a function from another file?

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

    First save the file in .py format (for example, my_example.py). And if that file have functions,

    def xyz():
    
            --------
    
            --------
    
    def abc():
    
            --------
    
            --------
    

    In the calling function you just have to type the below lines.

    file_name: my_example2.py

    ============================

    import my_example.py
    
    
    a = my_example.xyz()
    
    b = my_example.abc()
    

    ============================

提交回复
热议问题