简体   繁体   English

这是包装脚本吗? 正确的名字是什么? (蟒蛇)

[英]Is this a wrapper script? What is the correct name for it? (Python)

execfile("es.py")
execfile("ew.py")
execfile("ef.py")
execfile("gw.py")
execfile("sh.py")

print "--Complete--"

It is a kind of wrapper script, i guess, but there is no "correct name" for that as it is not very pythonic to write something like that. 我猜这是一种包装脚本,但是没有“正确的名称”,因为写这样的东西不是很Python。

One would probably write something like 一个人可能会写类似

import es
import ew
### ...

es.run() # assuming es code is in a run function
ew.run()
# ...

To expand on that, in python, a file is supposed to represent an unit of functionality. 为了对此进行扩展,在python中,一个文件应该代表一个功能单元。 For example, if you implement a list type / class, you might want to put the class for this type and every function related to it into this file. 例如,如果实现列表类型/类,则可能需要将此类型的类以及与之相关的每个函数放入此文件中。

In python, a function is supposed to be an unit of execution, eg. 在python中,功能应该是执行单元,例如。 a bunch of code that is supposed to run at once, on some particular data. 一堆应该在某些特定数据上立即运行的代码。 It's hard to advise you without knowing the content of the files, but the content of every file executed in your snippet of code would probably benefit from being put into functions. 在不知道文件内容的情况下很难建议您,但是在代码片段中执行的每个文件的内容都可能会受益于放入函数中。 The file division could be kept, or not depending on functionality. 可以保留文件划分,也可以不保留文件划分,具体取决于功能。

It seems more like a "batch" script. 它似乎更像是一个“批处理”脚本。 It looks analogous to writing a bash or batch file in unix/windows to do a bunch of pre-defined things. 它看起来类似于在unix / windows中编写bash或批处理文件以执行一堆预定义的事情。 I definitely agree that it's not really a pythonic thing to do as is written though. 我绝对同意,这并不是写的那样真正的pythonic事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM