-2

I have a .txt file that is not arranged properly and contains 11273 characters in one line I would like to arrange one character in one line and I am unable to do so because there is no space between characters. is one character and I want to arrange the .txt file like the output

Input (.txt file)

ABCD

Output (.txt file)

A
B
C
D
Khawar Islam
  • 2,556
  • 2
  • 34
  • 56

1 Answers1

0
with open("input.txt") as input, open("output.txt", "w") as output:
    output.write("\n".join(input.read()))
Nick McCurdy
  • 17,658
  • 5
  • 50
  • 82
  • 2
    You don't even need the `.split("")`, strings are iterable and hence a valid argument for `join`. – Abdul Aziz Barkat Mar 15 '23 at 05:55
  • SyntaxError: Non-UTF-8 code starting with '\xec' in file /media/cvpr/CM_22/doctr/missing_Characters.py on line 47, but no encoding declared; see https://python.org/dev/peps/pep-0263/ for details – Khawar Islam Mar 15 '23 at 06:11
  • 1
    @KhawarIslam That is a separate question (which is also a duplicate), your file isn't using UTF-8 encoding. See: [SyntaxError: Non-UTF-8 code starting with '\x91'](https://stackoverflow.com/questions/23092176/syntaxerror-non-utf-8-code-starting-with-x91) – Abdul Aziz Barkat Mar 15 '23 at 06:17
  • my text is Korean based but I can not write in StackOverflow they consider as a SPAM – Khawar Islam Mar 15 '23 at 06:18