Convert Fortran format specifiers to Python format strings.
Project description
Convert Fortran format specifiers to Python format strings.
Requirements
Python 3.5 or greater
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
Built Distribution
Hashes for fortran-format-converter-0.1.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 389fa8bc3ee46c0fdae7dd930c9fa6f0582755ffbb4a6bbb97e8559c2feb5559 |
|
MD5 | eb06c5ae212f082ee4a72d859b88db81 |
|
BLAKE2b-256 | e7d22edd076fc506f3e0ba3cb29c7bd81c43e07c3c7f25ee4f78379531cf260d |
Hashes for fortran_format_converter-0.1.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | df92d4ebad750f9d043143abef6517f82d676af6c0f7f21ca561996888d58192 |
|
MD5 | f189ffe38b0800f7b0bb5053deeb3968 |
|
BLAKE2b-256 | 9a92abfc900b7746742e99db17cab6584680a803f484508eb9f35409a5d60fca |