Equivalent for an internal write in Python ?

  • Thread starter Madhusudan Singh
  • Start date
M

Madhusudan Singh

Hi

I am looking to write a formatted string to a string variable :

Say I have 1.067e-01, I need to write 106.700 to some string.

In Fortran 95, this would be accomplished with a :

character(len=7) :: stringvar
real :: stringval

....

write(stringvar,'(f7.3)') stringval

How does one do something like this in Python ? I need a string formatted in
this way for one of my applications.
 
F

Fredrik Lundh

Madhusudan said:
I am looking to write a formatted string to a string variable :

Say I have 1.067e-01, I need to write 106.700 to some string.

In Fortran 95, this would be accomplished with a :

character(len=7) :: stringvar
real :: stringval

...

write(stringvar,'(f7.3)') stringval

How does one do something like this in Python ? I need a string formatted in
this way for one of my applications.

stringvar = "%.3f" % stringval

for details, see

http://docs.python.org/tut/node9.html
http://docs.python.org/lib/typesseq-strings.html

</F>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,266
Messages
2,571,318
Members
47,998
Latest member
GretaCjy4

Latest Threads

Top