shaharkadmiel / pySW4

Setup, run, post process, and visualize numerical simulations. Primarily SW4
http://shaharkadmiel.github.com/pySW4
GNU General Public License v3.0
28 stars 14 forks source link

read_input_file fails #4

Closed shaharkadmiel closed 8 years ago

shaharkadmiel commented 8 years ago
pySW4/core/config.pyc in read_input_file(filename)
     27         config_item = AttribDict()
     28         for item in line:
---> 29             key, value = item.split("=")
     30             config_item[key] = _decode_string_value(value)
     31         config_category.append(config_item)

ValueError: need more than 1 value to unpack

This happens because some of the station names have = signs in them. For some purposes this is important and I don't want to limit the user from using that... I'll take care of this later to make it more robust.

megies commented 8 years ago

Actually, it says need more than 1 value to unpack, so you're hitting a piece without an =. Maybe a stray space in there?

shaharkadmiel commented 8 years ago

Hmm... you are right

megies commented 8 years ago

The whole parsing the config is very crude/minimalistic right now, no assertions at all.. but it was enough for my purposes so far.

shaharkadmiel commented 8 years ago

I understand, I'm working on it right now. The reason it failed in this case was a comment on one of the lines after the command (not at the beginning...).

BTW, is there a reason to read the entire file and then parse it? is that quicker than reading line by line?

with open(filename) as f:
    for line in f:
        line = line.strip().split()
        ...
shaharkadmiel commented 8 years ago
...
['x=0.000', 'y=0.000', 'depth=0.000', 'file=surface_x=0.000_y=0.000_', 'writeEvery=100', 'variables=velocity']
file=surface_x=0.000_y=0.000_
...
pySW4/core/config.py in read_input_file(filename)
     31             print line
     32             print item
---> 33             key, value = item.split("=")
     34             config_item[key] = _decode_string_value(value)
     35         config_category.append(config_item)

ValueError: too many values to unpack

Now it is doing what I thought it was doing in the first place... So I was right too, well, sort off... ;)

megies commented 8 years ago

Should be fixed on master now.

shaharkadmiel commented 8 years ago

Ha! I was just about to commit mine... Thanks though.

megies commented 8 years ago

Ooops, sorry.. :blush: