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)

Project details

Download files

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

Source Distribution

fortran-format-converter-0.1.2.tar.gz (5.9 kB view hashes)

Uploaded Source

Built Distribution

fortran_format_converter-0.1.2-py3-none-any.whl (5.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page