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
• 27,640 points
36 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,050 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,070 points
79 views
0 votes
4 answers
0 votes
2 answers

how to print the current time using python?

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

answered Feb 14 in Python by Shashank
• 1,350 points
44 views
+2 votes
11 answers
0 votes
1 answer

How to print first character of each word in upper case of a string in Python

You can use split() using space as ...READ MORE

answered Jun 1, 2018 in Python by george
• 200 points
1,761 views
0 votes
1 answer

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

yes all are over TCP/IP connections secured by TLS encryption in hashgraph architecture-hashgraph, ...READ MORE

answered Aug 6, 2018 in Blockchain by ariaholic
• 7,340 points
75 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
138 views
0 votes
1 answer
+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,050 points
148 views