【发布时间】:2013-11-18 12:22:33
【问题描述】:
在一个瓶子路径中,我正在实例化一个类。
这个页面可能会被同时调用,并且需要在函数中创建名为“newuser”的类的同时实例。
我想确保不会发生冲突,因为函数为所有实例分配了名称“newuser”。
我认为这很好,因为类是在函数调用中创建的,并且类的范围应该只在函数本地?
from bottle import route, run
class user:
def __init__(self,id, name):
self.id = id
self.name = name
#Do some stuff that takes a while.
@route('/user/<id>/<name>', method = 'POST')
def test():
newuser = user(id, name)
run(host='localhost', port=8080, debug=True)
【问题讨论】:
标签: python class oop scope bottle