-2
我正在構建一個簡單的查詢生成器,但是當試圖測試它時似乎是Query.import_('')
返回一個類對象而不是字符串,因爲我在測試類型時得到了<'query.QueryBuilder'>
。反正它有一個字符串?__str__在類中沒有返回字符串
class Query(object):
"""
Query builder entry functions
"""
@classmethod
def _builder(cls):
return QueryBuilder()
@classmethod
def import_(cls, source_type):
return cls._builder().import_(source_type)
class QueryBuilder(object):
"""
Query Builder is the main class that generates sql
"""
def __init__(self, quote_char='"'):
self._from = []
self._import = None
self._source_type = None
self.quote_char = quote_char
def import_(self, source_type):
if source_type == SourceType.XML:
raise KeyError('Importing a XML is not supported')
self._source_type = source_type
return self
def __str__(self):
return self.get_sql(quote_char='"')
def get_sql(self):
if not (self._import):
return 'select 1 from dual'
return 'select 1 from dual'
你必須明確地調用'STR(QueryBuilder的())'如果你想有一個字符串;代碼中沒有提示'Query._builder()'應該返回一個字符串。 – chepner
爲什麼你期望或想要一個字符串? – user2357112
你爲什麼期望'__str__'參與? – user2357112