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 is on PyPI so the easiest way to install it is:
$ pip install fortran-format-converter
Usage
Currently fortran-format 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.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51f077b8aaa18089dc8631034088a3169ef7adc986d3367402343073e24d4381 |
|
MD5 | acddbebcde8904259b5f186e6d1553bb |
|
BLAKE2b-256 | 80a80e264c98b876fffface9da4b753b0741a57a4587f012169c136747cc265c |
Hashes for fortran_format_converter-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e723fccc0d94c5c2256436cca8689077cdb594fb46b4bd70a3c1bb0cd2df397 |
|
MD5 | b70e11a92c4d87a643b1873b8ceb1cbf |
|
BLAKE2b-256 | be1cf03ecf7533778c61e152bdae1fc8fe1bf0f4e7b2fe2ed28ee0f806d4dffc |