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.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4a467252d796c6b29ef7559970e03df16a0eb0f0eed736326bba5dba98853332 |
|
MD5 | 6c6266a79b6417c2592dce9ff14a05ff |
|
BLAKE2b-256 | 7ba7704f10edff9ad77ab179607e3957f1ad77310e17c1e2f731c046cda4df54 |
Hashes for fortran_format_converter-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 13ca618dcfb3c897de9b632144fa42cce0795611bf348a4a8c005571e4ae9238 |
|
MD5 | 9f5d9a626e24efa3860effa226a89e97 |
|
BLAKE2b-256 | 651ee3db7c7ace52c53170b91add919b1b0582cf8f7f6dcd4f7893fe3fb80483 |