如何链接多个脚本? [英] How to link multiple scripts?

查看:59
本文介绍了如何链接多个脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将函数分成不同的文件,就像使用c ++一样(一个驱动程序文件和一个用于不同类别函数的文件,最终在编译时将它们链接在一起).

I would like to separate my functions into different files like I do with c++ (a driver file and a file for different categories of functions that I end up linking together upon compilation).

让我们假设要创建一个简单的驱动程序"文件来启动主程序,并创建一个功能"文件,其中包含由驱动程序调用的简单功能以及功能"文件中的其他功能.

Let's suppose I want to create a simple 'driver' file which launches the main program and a 'function' file which includes simple functions which are called by the driver and other functions within the 'function' file.

我应该怎么做?由于python未编译,如何将文件链接在一起?

How should I do this? Since python is not compiled, how do I link files together?

推荐答案

您可以 import 模块.只需创建不同的python文件并在脚本开始时将其导入即可.

You can import modules. Simply create different python files and import them at the start of your script.

例如,我得到了这个 function.py 文件:

For example I got this function.py file :

def func(a, b):
    return a+b

还有这个 main.py 文件:

import function

if __name__ == "__main__":
    ans = function.func(2, 3)
    print(ans)

就是这样!这是有关导入模块的官方教程.

And that is it! This is the official tutorial on importing modules.

这篇关于如何链接多个脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆