我是 Python 新手,我可以直截了当地说,与你们中的许多人相比,我的编程经验是名义上的。振作起来:)
我有 2 个文件。我从本网站的用户那里找到的一个用 Python 编写的 GEDCOM 解析器(gedcom.py - http://ilab.cs.byu.edu/cs460/2006w/assignments/program1.html)和一个我提取的简单 GEDCOM 文件来自 heiner-eichmann.de/gedcom/gedcom.htm。猜猜谁在把 2 和 2 放在一起有困难?这家伙...
这是一个代码片段,后面是我到目前为止所做的事情。
class Gedcom:
""" Gedcom parser
This parser is for the Gedcom 5.5 format. For documentation of
this format, see
http://homepages.rootsweb.com/~pmcbride/gedcom/55gctoc.htm
This parser reads a GEDCOM file and parses it into a set of
elements. These elements can be accessed via a list (the order of
the list is the same as the order of the elements in the GEDCOM
file), or a dictionary (the key to the dictionary is a unique
identifier that one element can use to point to another element).
"""
def __init__(self,file):
""" Initialize a Gedcom parser. You must supply a Gedcom file.
"""
self.__element_list = []
self.__element_dict = {}
self.__element_top = Element(-1,"","TOP","",self.__element_dict)
self.__current_level = -1
self.__current_element = self.__element_top
self.__individuals = 0
self.__parse(file)
def element_list(self):
""" Return a list of all the elements in the Gedcom file. The
elements are in the same order as they appeared in the file.
"""
return self.__element_list
def element_dict(self):
""" Return a dictionary of elements from the Gedcom file. Only
elements identified by a pointer are listed in the dictionary. The
key for the dictionary is the pointer.
"""
return self.__element_dict
我的小剧本
import gedcom
g = Gedcom('C:\tmp\test.ged') //我在 Windows 上
print g.element_list()
从这里,我收到一堆输出“gedcom.Element instance at 0x00 ...”
我不知道为什么我会收到这个输出。我认为根据 element_list 方法会返回一个格式化的列表。我用谷歌搜索并搜索了这个网站。答案可能正盯着我看,但我希望有人能指出显而易见的事情。
非常感激。