,如果我的服务器,其中一个将使用更多的内存上运行的程序:我会分配值还是直接在其他变量中使用它们?
a = operation1()
b = operation2()
c = doOperation(a, b)
或directy:
a = doOperation(operation1(), operation2())
编辑:
1:我使用的CPython 。
2:我在问这个问题,因为有时,我在我的代码可读性的爱,所以不是写操作的looong序列,U只需将它们分割成变量。
EDIT2:
这里是全码:
class Reset(BaseHandler):
@tornado.web.asynchronous
@tornado.gen.engine
def get(self, uri):
uri = self.request.uri
try:
debut = time.time()
tim = uri[7:]
print tim
cod = yield tornado.gen.Task(db.users.find_one, ({"reset.timr":tim})) # this is temporary variable
code = cod[0]["reset"][-1]["code"] # this one too
dat = simpleencode.decode(tim, code)
now = datetime.datetime.now() # this one too
temps = datetime.datetime.strptime(dat[:19], "%Y-%m-%d %H:%M:%S") # this one too
valid = now - temps # what if i put them all here
if valid.days < 2:
print time.time() - debut # here time.time() has not been set to another variable, used directly
self.render("reset.html")
else:
self.write("hohohohoo")
self.finish()
except (ValueError, TypeError, UnboundLocalError):
self.write("pirate")
self.finish()
,你可以看到有变数,只有即暂时有用。
这完全取决于是否doDoperation()将存储对传入的参数的引用。 – 2013-02-08 14:45:58
@MartijnPieters - 当垃圾回收器实际运行时,我想... – mgilson 2013-02-08 14:48:03
@mgilson:在CPython对象在ref计数下降到0时被删除;垃圾收集器主要用于检测和破坏循环引用。 – 2013-02-08 14:50:03