how to call a function from another file?

前端 未结 1 418
耶瑟儿~
耶瑟儿~ 2020-12-09 02:07

Sorry basic question I\'m sure but I can\'t seem to figure this out.

Say I have this program , the file is called pythonFunction.py:

def         


        
相关标签:
1条回答
  • 2020-12-09 02:30

    You need to print the result of calling the function, rather than the function itself:

    print pythonFunction.function()
    

    Additionally, rather than import pythonFunction as pythonFunction, you can omit the as clause:

    import pythonFunction
    

    If it's more convenient, you can also use from...import:

    from pythonFunction import function
    print function() # no need for pythonFunction.
    
    0 讨论(0)
提交回复
热议问题