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,620 points
17 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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,040 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,050 points
54 views
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
19 views
+2 votes
11 answers

How to print array/ list without brackets in python?

name=["a","b","c"] print (', '.join(name)) It will simply take all ...READ MORE

answered Apr 18, 2018 in Python by aayushi
• 750 points
12,195 views
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,046 views
0 votes
1 answer

How to get text label from SAP using pywinauto[python]

Hi. Can you please tell me what ...READ MORE

answered Jun 28, 2018 in Python by Nietzsche's daemon
• 4,260 points
209 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,320 points
43 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
65 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,040 points
89 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.