Answers for "UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 35"

0

UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 92: character maps to <undefined>

file = open(filename, encoding="cp437")
Posted by: Guest on June-26-2020
0

UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position 550: character maps to <undefined>

#Filename                       Read_file.py
#Author                         Steve Morse
#Date                           5/30/2020
# Cleaned up					9/30/2020

x=" "



# process_lines DID NOT WORK AT FIRST
# I had fogotten that the EOL (end of line) charcter/values were 
# still attached to the line
# .strip() got rid of them, no problem



# All this does is print out the line.

def process_lines(line, count):
    x=""
    print(count)
    #print(line)
    line2=line.strip()        # This strips the offending EOL chars
    #print(line2)
    
    
    # This is my code for finishing the loop
    if line2=='Order Number:':
        x=''
        print(line2)
        print('xxxxxxxxxxxxxxxxxxxxxx')
        x=input('Enter to continue, X to finish')



    if x=='x':
        return 'x'
    if x=='X':
        return 'x'

    print("nn")
    return x





#=========================================================
Main Routine

#Orders is a BIG file encoded UTF-8
#Orders1 is a SMALL file encoded UTF-8 (1st 5 entries of Orders)


#Initially I had an error
#    'utf-8' codec can't decode byte 0xe2 : invalid continuation byte error
#
# This was solver with the following:
#                                                                      encoding="UTF-8"


counter=0


with open('orders1.txt', 'r',encoding="UTF-8") as f:
    for line in f:
        counter +=1    
        xx=process_lines(line, counter)
        if xx=='x':
            break




        
#=========================================================
# So I know it has finished

print("nnn========================================nFinished")
Posted by: Guest on May-31-2020

Code answers related to "UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 35"

Python Answers by Framework

Browse Popular Code Answers by Language