[英]python import module vs running script as subprocess.popen
Suppose I have python script having having 4-5 functions all are called from single function in a script. 假设我有一个具有4-5个函数的python脚本,所有脚本都从单个函数中调用。 If I want to results after executing script( Use functions from another script) I can make script executable and use subprocess.popen and I can also import these functions in another script.
如果我想在执行脚本后得到结果(使用另一个脚本中的函数),则可以使脚本可执行并使用subprocess.popen,也可以将这些函数导入另一个脚本中。 Which is better way to do this?
哪种更好的方法呢?
Which is better way to do this?
哪种更好的方法呢?
Use import
unless you have to use subprocess.Popen
to run Python code. 除非必须使用
subprocess.Popen
来运行Python代码,否则请使用import
。
import
uses sys.path
to find the module; import
使用sys.path
查找模块; you don't need to specify the path explicitly If you want to use functions from an other script then you usually import the script. 如果要使用其他脚本中的功能,则通常会导入该脚本。
When the script is script.py
you can write import script
and use the functions that are defined in the script with script.function_in_the_script
. 当脚本为
script.py
您可以编写import script
,并将脚本中定义的函数与script.function_in_the_script
一起script.function_in_the_script
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.