eisha enan
eisha enan

Reputation: 41

Having problem while copying text data from one txt file to another in python

I have a file text.txt that contains text data: this is a text file
then I have a test.text that is primarily empty.

from sys import argv

script, from_file, to_file = argv

out_file = open(to_file, 'w').write((open(from_file).read()))

when I run that code the test.txt file gets copied text from text.txt file and it is:

this is a text file਍ഀ
਍ഀ

why do I get those rectangular blocks?? How to fix it??

Upvotes: 0

Views: 282

Answers (1)

snakecharmerb
snakecharmerb

Reputation: 55962

If you look closely at the "rectangular blocks" you can see that they contain the rows

0A

and

0D

which are the hex representations of '\n' and '\r' respectively. So the blocks are your editor's way of showing you these characters, which are used in Windows to mark the end of a line in a text file and which are usually invisible.

Upvotes: 1

Related Questions