473,387 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Equivalent for an internal write in Python ?

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
2 1129
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: David MacKay | last post by:
Dear Greater Py, <motivation note="reading this bit is optional"> I am writing a command-line reader for python. I'm trying to write something with the same brevity as perl's one-liner ...
2
by: mirandacascade | last post by:
Situation is this: 1) must write application that does the following: a) creates an xml document, the contents of which, is a request transaction b) send xml document to destination; I am...
10
by: Neuruss | last post by:
I'm sorry for asking about another language here, but since I only know Python and I'm trying to write something in C#, I guess this is the best place... I'd like to know how to write this in...
10
by: Bishoy | last post by:
Hi, In VB.NET there is a keyword called "My" which has a lot of properties collected at it. Is there any equivalent to this "My" in C#? Thank you.
6
by: openopt | last post by:
Thank you in advance for your response. Dmitrey
3
by: dmitrey | last post by:
Thank you in advance, Dmitrey
1
by: Hishaam | last post by:
How to execute commands in internal zones of solaris using python running from the global zone ? i tried -- 1os.popen("zlogin <zone1>") 2os.popen("zonename") the 2nd command executes back...
22
by: Kurien Mathew | last post by:
Hello, Any suggestions on a good python equivalent for the following C code: while (loopCondition) { if (condition1) goto next; if (condition2) goto next;
8
by: Derek Martin | last post by:
I'd like to know if it's possible to code something in Python which would be equivalent to the following C: ---- debug.c ---- #include <stdio.h> bool DEBUG;
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.