Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write multiple strings into a text file as a single line

I want to write something as one line such as:

Blah blah 123456 0.0000123

I used the below code:

value1 = 123456
value2 = 0.0000123
k = "Blah blah" + value1 +value2
File.write(k)
#outFile.write("Blah blah %s %s" % (value1 ,value2) )

The output is always:

Blah blah 123456
0.0000123
like image 538
GigI Avatar asked Jan 18 '26 09:01

GigI


1 Answers

Integers when concatenated with strings have an assumed endline character afterwards. To remedy this problem, you can convert these ints to strings before concatenating all of them. You can do this with the str() function which is written about here: https://docs.python.org/2/library/functions.html

like image 162
JoshKopen Avatar answered Jan 21 '26 02:01

JoshKopen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!