Is it possible to use a fortran-like font in python?

Is it possible to somehow "type" in python in fortran like this?

1     4.5656
2    24.0900
3   698.2300
4    -3.5000

So, decimal points are always in the same column, and we always get 3 or n decimal numbers?

thank

+5
source share
6 answers
>>> '%11.4f' % -3.5
'    -3.5000'

or formatting a new style:

>>> '{:11.4f}'.format(-3.5)
'    -3.5000'

more about format specifiers in documents .

+9
source

You can also see the library fortranformaton the PyPI page or, if you want to completely recreate the text IO FORTRAN.

If you have questions, send me a letter (I wrote it).

+5
source
for i in [(3, 4.534), (3, 15.234325), (10,341.11)]:
...     print "%5i %8.4f" % i
... 
    3   4.5340
    3  15.2343
   10 341.1100
0
print "%10.3f" % f

f ( : %-10.3f ). 10 ( s > 10 ) 3 . :

f = 698.230 # <-- 7 characters when printed with %10.3f
print "%10.3f" % f # <-- will print "   698.2300" (two spaces)

:

print "\n".join(map(lambda f: "%10.3f" % f, [4.5656, 24.09, 698.23, -3.5]))
0

string.rjust(), :

a = 4.5656
b = 24.0900
c = 698.2300
d = -3.5000

a = "%.4f" % a
b = "%.4f" % b
c = "%.4f" % c
d = "%.4f" % d

l = max(len(a), len(b), len(c), len(d))

for i in [a, b, c, d]:
        print i.rjust(l+2)

:

~ $ python test.py 
    4.5656
   24.0900
  698.2300
   -3.5000
0

Fortran io C io.

fortranformat Brendan.

https://pypi.python.org/pypi/fortranformat

easy_install fortranformat

fortran , C.

0

All Articles