【发布时间】:2014-06-17 13:53:15
【问题描述】:
我已经在我的项目中使用了很多小函数和代码 sn-ps。
例如,围绕库执行常见任务的包装器:
def DownloadFile(url, filename):
output = open(filename,'wb')
output.write(urllib.request.urlopen(url).read())
output.close()
或者,一种捕获和忽略错误的快速方法:
def deleteFile(f):
if f == "":
pass
else:
try:
os.remove(f)
except:
print("Cant delete ",f)
我有很多这样的功能,我正在使用它们来调用它们
sys.path.append('../../blah')
import lib_file as fle
我的问题是,处理这个问题的首选方法是什么:
a) 将它们放入适当的库中并导入
b) 熟练使用标准 Python 库,因此您不需要包装器
c) 还有另一种重用 Python sn-ps 的方法吗? (除了复制粘贴)
【问题讨论】:
标签: python architecture module python-import code-reuse