我正在尝试使用任何一个基于libxml的第三方XML解析器,但我不能,因为我认为我有某种类型的libxml2问题
我将其他链接器标志设置为-lxml2
和/ usr/include/libxml2的标题搜索路径
但是当我尝试编译时,我仍然会得到大量未定义的符号.以下错误是尝试编译TouchXML的结果.
Undefined symbols:
"_xmlDocDumpFormatMemory", referenced from:
-[CXMLDocument description] in CXMLDocument.o
"_xmlXPathNewContext", referenced from:
-[CXMLNode nodesForXPath:error:] in CXMLNode.o
-[CXMLNode(CXMLNode_NamespaceExtensions) nodesForXPath:namespaceMappings:error:] in CXMLNode_XPathExtensions.o
"_xmlOutputBufferFlush", referenced from:
-[CXMLNode XMLStringWithOptions:] in CXMLNode.o
"_xmlNodeListGetString", referenced from:
-[CXMLNode stringValue] in CXMLNode.o
"_xmlFree", referenced from:
_xmlFree$non_lazy_ptr in CXMLDocument.o
_xmlFree$non_lazy_ptr in CXMLNode.o
(maybe you meant: _xmlFree$non_lazy_ptr)
"_xmlXPathFreeContext", referenced from:
-[CXMLNode nodesForXPath:error:] in CXMLNode.o
-[CXMLNode(CXMLNode_NamespaceExtensions) nodesForXPath:namespaceMappings:error:] in CXMLNode_XPathExtensions.o
"_xmlNodeDumpOutput", referenced from:
-[CXMLNode XMLStringWithOptions:] in CXMLNode.o
"_xmlAddChild", referenced from:
-[CXMLDocument(CXMLDocument_CreationExtensions) addChild:] in CXMLDocument_CreationExtensions.o
-[CXMLElement(CXMLElement_CreationExtensions) addChild:] in …Run Code Online (Sandbox Code Playgroud) 假设我有一个元组列表:
fruits = [('apple','red',23),
('apple','green',12),
('orange','small',12),
('orange','large',1)]
Run Code Online (Sandbox Code Playgroud)
如何快速,干净地创建一个新列表,其中包含具有最大数字但对于水果名称唯一的元组.所以理想的结果是:
fruits = [('apple','red',23),
('orange','small',12)]
Run Code Online (Sandbox Code Playgroud)
我目前的方法是这样的:
def check_fruit(fruit, a_list):
for item in a_list:
if fruit[0] == item[0] and fruit[2] < item[2]:
return False
return True
filtered_list = [fruit for fruit in fruits if check_fruit(fruit, fruits)]
Run Code Online (Sandbox Code Playgroud)
如果有更好的方法,请告诉我!谢谢.
我当前的表设置用于“单词”和“短语”之间的多对多关联:
association_table_wp = Table('words_phras', Base.metadata,
autoload=True,
extend_existing=True)
class Phrase(Base):
__tablename__ = 'phrases'
__table_args__ = {'autoload': True}
def __init__(self, phrase, explanation=None, active=False):
self.phrase = phrase
self.explanation = explanation
self.active = active
class Word(Base):
__tablename__ = 'words'
__table_args__ = {'autoload': True}
def __init__(self, word, word_id=None, active=False):
self.word = word
self.word_id = word_id
self.active = active
Word.phrases = relationship(Phrase,
secondary=association_table_wp,
backref="words")
Run Code Online (Sandbox Code Playgroud)
现在通常当我想查找一些单词及其短语时我使用:
words = db_session.query(Word).filter(Word.id.in_(word_ids)).\
options(joinedload(Word.phrases)).\
all()
Run Code Online (Sandbox Code Playgroud)
这允许我访问words[i].phrases与给定单词相关的短语。
现在,这工作正常,但请注意“active”属性。我想过滤单词的短语,以便只active == True返回带有 的短语。如何才能做到这一点?我尝试了几种连接和 eager_loading 的组合,但没有一个像我希望的那样工作。
非常感谢。
filter ×2
python ×2
filtering ×1
gdata ×1
ios ×1
libxml2 ×1
list ×1
many-to-many ×1
sqlalchemy ×1
touchxml ×1