2017-02-09 20 views
1

開始方法についてはわかりません。私はデータベースに入れることができるたくさんのタブ区切りファイルを持っています。しかし、難しい部分は、テーブルが最善の方法でレイアウトされていないということです。たとえば、親行には文字(D)が指定され、その親の下にある行は次のD行がリストされるまで親に対応します。ネストしたテーブル/スプレッドシートを反復する

理想的には、すべての子行を親。データのhttp://www.gasnom.com/ip/vector/archive.cfm?type=4

より良い視覚的な表現、誰がそれを言及する前に、私はHTMLをこすりすることはできません。(別の方法が存在しない限り)データベースとクエリ結果に

をそれを置くためにここでは、データへのリンクですこれは対応するWebサイトを持つ唯一のデータファイルです。

http://www.vector-pipeline.com/Informational-Postings/Index-of-Customers.aspx

答えて

0

私はこれがうまくいくと思います。 "親"行のリストの各 "親"行の末尾に "子"行のリストを追加するだけです。

customer_file = open('index_of_customers.txt', 'r') # you should of course do more try-except stuff in your script 
database = []          # all data ends up here 
for each_line in customer_file:      # reads one line at a time 
    each_line = each_line.strip('\n')    # removes newlines 
    each_line = each_line.split('\t')    # split the line of text into a list. This should save any empty columns aswell 
    if each_line[0] == 'D':       # if line starts with a single D 
     each_line.append([])      # add a list for the other lines at the end of the D line 
     database.append(each_line)    # add a D line to the "database" as a list 
    else:           # if line don't start with a single D 
     if len(database):       # the first line is not a D line, so we need to check if the database is empty to avoid errors 
      database[-1][-1].append(each_line)  # add the line to the last D line's list. 
for each_D_line in database:      # prints out the database in an ugly way 
    print(str(each_D_line[:-1]))     # first the D lines 
    for each_other_line in each_D_line[-1]: 
     print('\t' + str(each_other_line))  # then each other line 
関連する問題