【发布时间】:2019-03-21 21:11:48
【问题描述】:
我正在使用 Python 脚本读取一些 ASCII 文件,操作它们的值并获得输出。计算是在类实例化中完成的,类似于伪形式
def __init__(input)
self.input = input
self.output = function of input
伪代码,在问号之间有争议的部分,是
open file
read lines
for each lines in file:
split line
construct class instance with input from split-line values
store instance.output in a help variable (list)
?? delete class instance ??
further processing of the help variable
etc
删除类实例是节省时间和内存的障碍还是机会?问题的规模很大(不足 100 万行)。
我很清楚我宁愿从二进制文件中读取,但目前这不可行。另外,我选择类构造是因为优雅,也许随着脚本的发展,我可以从封装中获得更多好处。但是,如果有人建议这样做,我可以在这个阶段放弃它。
【问题讨论】:
-
根据我对python中垃圾收集器的了解,一旦一个对象变得无法访问,它就会被垃圾收集——如果你用相同的引用重新定义构造的类,你就无法到达初始对象并且它会被垃圾收集反正
标签: python performance loops class destructor