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.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | fcb27a8550aaa292aaa7371b239a796c7bc47236bc82a0c4072b7b013f121c9a |
|
MD5 | 46e3e0de904765a2994cb4d252a02855 |
|
BLAKE2b-256 | c44ed0fe3b2fdc15779155b403fa7dbeeba6849f7aba730bc4f1a1355575472d |
Hashes for fortran_format_converter-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae46623fdfa7852ac7ee3622f6b171932b2c655b9c48790e83392a433eb791aa |
|
MD5 | a8c7f06d5c372d3e32703c302938a729 |
|
BLAKE2b-256 | a997500b35a7970a9183b4321e6297842ec2787b9da23e29515e62ef7b962180 |