G edit descriptor in output

Issue #16 resolved
created an issue


In some cases, I encountered problems when trying to create output with the G edit descriptor. For example, the script

import fortranformat t = 0.0 fmtline = fortranformat.FortranRecordWriter('(G10.2)') print fmtline.write([t])

(normally, the output should be just "0.0") stops with the error message

Traceback (most recent call last): File "python_format.py", line 7, in <module> print fmtline.write([t]) File "/home/braun/.python/fortranformat/FortranRecordWriter.py", line 48, in write return _output(self._eds, self._rev_eds, values) File "/home/braun/.python/fortranformat/_output.py", line 128, in output sub_string = _compose_float_string(w, e, d, state, val, 'G') File "/home/braun/.python/fortranformat/_output.py", line 316, in _compose_float_string out = _output_float(w, d, e, state, ftype, buff, sign_bit, zero_flag, ndigits, edigits) File "/home/braun/.python/fortranformat/_output.py", line 425, in _output_float if (nbefore + nafter) == 0: UnboundLocalError: local variable 'nbefore' referenced before assignment

Comments (2)

  1. Brendan Arnold repo owner

    It turns out that the 'G' edit descriptor was not handling the '0' case correctly. It should be fine now and act according to the spec which is using the 'E' edit descriptor.

    This has been released as 0.2.5 with a test to cover it.

  2. Log in to comment