UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 6148: character maps to <undefined>
Add encoding:
file = open(filename, encoding="utf8")
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 6148: character maps to <undefined>
Add encoding:
file = open(filename, encoding="utf8")
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 92: character maps to <undefined>
#that's worked for me
file = open(filepath,"r", encoding="utf8")
'charmap' codec can't decode byte 0x9d in position 846: character maps to <undefined>
file = open(filename, encoding="utf8")
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("\n\n")
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("\n\n\n========================================\nFinished")
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us