私はPythonを初めて使用しますが、多くの人と比較して、私のプログラミング経験はごくわずかであると言えます。気を引き締めてください:)
2つのファイルがあります。このサイト(gedcom.py-http://ilab.cs.byu.edu/cs460/2006w/assignments/program1.html)のユーザーから見つけたPythonで記述されたGEDCOMパーサーと私がプルした単純な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 at0x00...」を受け取ります。
この出力を受け取っている理由がわかりません。element_listメソッドに従って、フォーマットされたリストが返されると思いました。私はグーグルでこのサイトを検索しました。答えはおそらく私を正面から見つめていることですが、誰かが明白なことを指摘してくれることを望んでいました。
とても有難い。