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

Requirements

Installation

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

$ pip install fortran-format-converter

Usage

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')
'6.2f'

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

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

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)
 2.72

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.3.tar.gz (6.1 kB view hashes)

Uploaded Source

Built Distribution

fortran_format_converter-0.1.3-py3-none-any.whl (6.1 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