Skip to main content

Convert Fortran format specifiers to Python format strings.

Project description

Convert Fortran format specifiers to Python format strings.

Build status Test coverage

PyPI Package latest release Supported versions PyPI Wheel Status



fortran-format-converter is on PyPI so the easiest way to install it is:

$ pip install fortran-format-converter


Currently fortran-format-converter only handles simple conversions and in a single direction, Fortan -> Python.

We begin by importing the converter.

import fortran_format_converter as ffc

Now to convert a Fortran style format specification to a Python format string is as simple as supplying the convert function with the Fortran formatting specification.

>>> ffc.convert('F6.2')

Most types of Fortran format specifications are supported, such as binary.

>>> ffc.convert('B16.16')

If an invalid format string is given an error will be raised.

>>> ffc.convert('J4')
Traceback (most recent call last):
ValueError: 'J4' is not a valid Fortran format specifier

Sometimes it may be desirable to parameterized the format. This can be accomplished with the width, align, and precision fields of the Format class.

>>> format = ffc.Format('F5.2')
>>> '{:{width}.{prec}f}'.format(2.718281828459, width=format.width, prec=format.precision)


fortran-format-converter is a best effort converter, many Fortran format strings are not convertible to Python format strings. When the format is not compatible a similar but not necessarily identical format will be used.

If Fortran identical formatting is desired you should look into the excellent fortranformat package by Brendan Arnold which reads or writes directly without translation through Python format strings. fortran-format-converter is intended for applications where a Python compatible format string (and not the result) is required, such as for matplotlib tick formatting.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for fortran-format-converter, version 0.1.3
Filename, size & hash File type Python version Upload date
fortran_format_converter-0.1.3-py3-none-any.whl (6.1 kB) View hashes Wheel py3
fortran-format-converter-0.1.3.tar.gz (6.1 kB) View hashes Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page