Formatting text.

M

Marcin Tyman

Hi again :)
Is there any way to format a string. I.E. I've got a variable which may
be 1, 2, 3 and the variable is added to string. I want to show whole
string formatted as follows:
100
1
10
1100

not like that:
100
1
10
1100

Any help would be helpful (as always ;-) )

thanks in advance
 
R

Robert Klemme

2007/7/25 said:
Hi again :)
Is there any way to format a string. I.E. I've got a variable which may
be 1, 2, 3 and the variable is added to string. I want to show whole
string formatted as follows:
100
1
10
1100

not like that:
100
1
10
1100

Any help would be helpful (as always ;-) )

Please look for printf, sprintf and % in the docs. The last one might
be hard to find. You use it as: "%3d" % 1

Kind regards

robert
 
M

Marcin Tyman

Robert said:
Please look for printf, sprintf and % in the docs. The last one might
be hard to find. You use it as: "%3d" % 1

Kind regards

robert

OK, Fine. But... I want to format the string not its output to redirect
the string to a file on remote machine (the file should be formatted).
 
S

Sebastian Hungerecker

Marcin said:
Robert Klemme wrote:

OK, Fine. But... I want to format the string not its output to redirect
the string to a file on remote machine (the file should be formatted).

sprintf and % return a string, they don't print anything to the screen. You
can write the result of "%3d" % 1 to a file without a problem.
 
R

Robert Klemme

2007/7/25 said:
OK, Fine. But... I want to format the string not its output to redirect
the string to a file on remote machine (the file should be formatted).

Now what? Do you want to output or not? I do not understand your
remark because with the methods I listed you can do output as well as
change strings.

robert
 
P

Peña, Botp

RnJvbTogTWFyY2luIFR5bWFuIFttYWlsdG86bS50eW1hbkBpbnRlcmlhLnBsXSANCiMgT0ssIEZp
bmUuIEJ1dC4uLiBJIHdhbnQgdG8gZm9ybWF0IHRoZSBzdHJpbmcgbm90IGl0cyBvdXRwdXQgDQoj
IHRvIHJlZGlyZWN0IHRoZSBzdHJpbmcgdG8gYSBmaWxlIG9uIHJlbW90ZSBtYWNoaW5lICh0aGUg
ZmlsZSANCiMgc2hvdWxkIGJlIGZvcm1hdHRlZCkuDQoNCnRoZSBzaW1wbGUgd2F5IGlzIGp1c3Qg
ZG8gdGhlIG91dHB1dCBvbiBzY3JlZW4gKGluIGEgZm9ybWF0IHlvdSB3YW50KS4gdGhlbiBpZiB5
b3UncmUgaGFwcHkgd2l0aCB0aGUgb3V0cHV0LCBqdXN0IHJlZGlyZWN0IGl0IHRvIGEgZmlsZS4N
Cg0KbGlrZSBlZywNCg0KcnVieSBteXRlc3Rwcm9ncmFtLnJiID4gbXlmaWxlDQoNCmp1c3QgdHJ5
IGl0Lg0KDQpraW5kIHJlZ2FyZHMgLWJvdHANCg==
 

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

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top