Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Handling a .txt text
#6
Thank you guys for the help!
I'm moving forward with your tips, but it breaks me another issue.

f = open("file.txt", "r")

for line in f:

    for item in line.split(' '):

        if "NET" in item.upper():

            print(line)

        else:
            pass

f.close()
When I open a .txt with more data the return of this code is the error below at PyCharm:

Error:
File "C:\Users\Lzr\AppData\Local\Programs\Python\Python37-32\lib\encodings\cp1252.py", line 23, in decode return codecs.charmap_decode(input,self.errors,decoding_table)[0] UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 4748: character maps to <undefined>
I'm wondering there is something wrong in the .txt file but there will be a way to treat this "decode" error.
Thank you again!!

PS.: I liked the way to open the file using 'with'.
Reply


Messages In This Thread
Handling a .txt text - by reinalazaro - Jan-09-2020, 01:27 AM
RE: Handling a .txt text - by ichabod801 - Jan-09-2020, 03:18 AM
RE: Handling a .txt text - by Clunk_Head - Jan-09-2020, 03:24 AM
RE: Handling a .txt text - by sandeep_ganga - Jan-09-2020, 03:26 AM
RE: Handling a .txt text - by perfringo - Jan-09-2020, 11:09 AM
RE: Handling a .txt text - by reinalazaro - Jan-11-2020, 01:59 AM
RE: Handling a .txt text - by Clunk_Head - Jan-11-2020, 02:16 AM
RE: Handling a .txt text - by reinalazaro - Jan-11-2020, 09:24 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Star python exception handling handling .... with traceback mg24 3 1,322 Nov-09-2022, 07:29 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020