我正在尝试使用 Python 中的流畅接口。
流畅的 sql 查询生成器的示例在使用中看起来像这样:
sql.select('foo').select('bar').from('sometable').tostring()
我很快意识到递归定义嵌套类的能力可能会有所帮助。
class sql:
class select:
class select # <-- HERE
def __init__(self, dbcolumn, astype=None, asname=None):
self.dbcolumn = dbcolumn
self.astype = astype
self.asname = asname
在标有注释“# <-- HERE”的行中:
我希望这个嵌套类引用引用包含类的相同“选择”类定义。
这有可能吗?也许使用一些我不知道的关键字?