By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,235 Members | 1,057 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,235 IT Pros & Developers. It's quick & easy.

Equivalent for an internal write in Python ?

P: n/a
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.
Sep 1 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Madhusudan Singh wrote:
Say I have 1.067e-01, I need to write 106.700 to some string.
Uh, I'm going to assume you meant 1.067e2, because 1.067e-01 != 106.700.
character(len=7) :: stringvar
real :: stringval

...

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

stringval = 1.067e2
stringvar = "%7.3f" % stringval
stringvar

'106.700'

String formatting is described here:

http://docs.python.org/lib/typesseq-strings.html
--
Michael Hoffman
Sep 1 '05 #2

P: n/a
Madhusudan Singh wrote:
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>

Sep 1 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.