我正在尝试扩展一点BibDesk中用于管理组的特性集,我想从一个程序中操作bibtex注释,BibDesk在其中写下静态组的信息。你知道吗
要做到这一点,我需要一个系统和强大的方式,以获得所有这是在bibtex文件的评论部分。你知道吗
@comment{BibDesk Static Groups{
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<dict>
<key>group name</key>
<string>MyGroupName</string>
<key>keys</key>
<string>BitexRefId1,BitexRefId2</string>
</dict>
</array>
</plist>
}}
一旦我着手处理XML array
,我想我知道如何处理它,但是第一部分,获取@comment{BibDesk Static Groups{
对我来说有点棘手。
我知道如何用sed
使用sed -e '/@comment{BibDesk Static Groups{/,/}/!d' test.bib
来实现它,但是pythonic的方法是什么呢?
我最拿手的就是一个本土的解析器
file = open(file_name,"r")
for line in file:
if static_groups_group:
if "}" in line:
static_groups_group=False
print "ending static group block"
if static_groups_group:
xml_groups.append(line)
if "@comment{BibDesk Static Groups{" in line:
print line," found"
static_groups_group=True
这是对
sed
命令的快速而肮脏的翻译。不过,我不一定推荐这种方法,因为它不是特别健壮。你知道吗相关问题 更多 >
编程相关推荐