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 File type Python version Upload date Hashes
Filename, size fortran_format_converter-0.1.3-py3-none-any.whl (6.1 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size fortran-format-converter-0.1.3.tar.gz (6.1 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page