Ignore:
Timestamp:
6 Jun 2012, 01:11:19 (13 years ago)
Author:
uli
Message:

Provide the more robust CSV file merging.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/utils/helpers.py

    r8631 r8633  
    658658    This CSV file merging copes with different column orders in both
    659659    CSV files and even with different column sets in both files.
     660
     661    Also broken/empty CSV files can be handled.
    660662    """
    661663    # sniff the col names
    662     row10 = csv.DictReader(open(path1, 'rb')).next()
    663     row20 = csv.DictReader(open(path2, 'rb')).next()
     664    try:
     665        row10 = csv.DictReader(open(path1, 'rb')).next()
     666    except StopIteration:
     667        row10 = dict()
     668    try:
     669        row20 = csv.DictReader(open(path2, 'rb')).next()
     670    except StopIteration:
     671        row20 = dict()
    664672    fieldnames = sorted(list(set(row10.keys() + row20.keys())))
    665673    # now read/write the real data
Note: See TracChangeset for help on using the changeset viewer.