Python how to print long text on different lines

0 votes

In my code I have python opening a text document and printing a HTML document in to it. by doing so it gives me a long sentence with ";" in it

Example of text in the text document

Total:0.01358324;BTC:0.00000000;LTC:0.00000001;BC:0.00000000;NMC:0.00000000;DOGE:63.71131428;NAUT:0.00017886;DRK:0.00000000;VTC:0.00013866;FTC:0.00000000;CURE:0.00025881;PPC:0.00000000;CHARITY:0.00000000;GHS:0.00003646;GHSOCT:0.00000000;GHSAUG:0.00000000;SCRYPT:200.09600305

How would I write or edit the file so every ";" forces a new line. I currently use this line to write a file called file.

file.write(response.read().decode('utf-8'))
Sep 5, 2018 in Python by digger
• 26,740 points
1,483 views

1 answer to this question.

0 votes

replace with a newline char.

 file.write(response.read().decode('utf-8').replace(";","\n"))

In [72]: line = "Total:0.01358324;BTC:0.00000000;LTC:0.00000001;BC:0.00000000;NMC:0.00000000;DOGE:63.71131428;NAUT:0.00017886;DRK:0.00000000;VTC:0.00013866;FTC:0.00000000;CURE:0.00025881;PPC:0.00000000;CHARITY:0.00000000;GHS:0.00003646;GHSOCT:0.00000000;GHSAUG:0.00000000;SCRYPT:200.09600305"

In [73]: print (line.replace(";","\n"))
Total:0.01358324
BTC:0.00000000
LTC:0.00000001
BC:0.00000000
NMC:0.00000000
DOGE:63.71131428
NAUT:0.00017886
DRK:0.00000000
VTC:0.00013866
FTC:0.00000000
CURE:0.00025881
PPC:0.00000000
CHARITY:0.00000000
GHS:0.00003646
GHSOCT:0.00000000
GHSAUG:0.00000000
SCRYPT:200.09600305
answered Sep 5, 2018 by slayer
• 29,370 points

Related Questions In Python

0 votes
0 answers

How to read lines from compressed text files in Python

Is it easy to read a line ...READ MORE

Dec 27, 2018 in Python by Anirudh
• 2,090 points
969 views
0 votes
4 answers
0 votes
1 answer

How to print colored text in terminal in Python?

Hello @kartik, You can use  Python termcolor module. Usage ...READ MORE

answered Jun 5, 2020 in Python by Niroj
• 82,840 points
3,432 views
0 votes
1 answer

How to print colored text in Python?

This somewhat depends on what platform you ...READ MORE

answered Dec 17, 2020 in Python by Gitika
• 65,770 points
1,482 views
0 votes
2 answers

how to print the current time using python?

print(datetime.datetime.today()) READ MORE

answered Feb 14, 2019 in Python by Shashank
• 1,370 points
1,124 views
+1 vote
1 answer

Protocols used in a distributed/dlt system for the nodes to establish communication

yes all are over TCP/IP connections secured ...READ MORE

answered Aug 6, 2018 in Blockchain by aryya
• 7,460 points
1,427 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,922 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,451 views
0 votes
2 answers
+7 votes
2 answers

I want to build a recommender system incorporating diversity and accuracy in the recommender engine.

I dont know what exactly you are ...READ MORE

answered Sep 24, 2018 in Python by slayer
• 29,370 points
2,118 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP