Error when opening 4GB txt file with Python

Keywords: python file-io unidecoder


I got a problem opening a 4GB txt file with python, I try opening the file with:

with open("C:\XXX.txt", 'r', encoding='utf-8-sig') as infile:
    for l in infile:

It doesn't show error but it is not printing anything, also if I try this code:

with open(r"C:\XXXX.txt", 'r', encoding='utf-8-sig') as infile:

It shows the following error:

File "<ipython-input-71-fd562e8c0fc6>", line 2, in <module>
TypeError: object of type '_io.TextIOWrapper' has no len()

When I try to open with NotePad or other text editor it says the file is too large to open, when I try to open with PyCharm it shows the file empty,

How Can I know which kind of content is inside this 4GB file with .txt extension?