Someone gave me this string: "Al BaÅ£á ̧©ah" (it's probably an Arabic name), and asked me to translate it (and a list of other similar strings) in Python.
This website converts it to "Al Baţḩah" with the operation "UTF8 Decode". I'm trying to do the same in Python, but is what I tried and my results. Most of the examples took a series of unicode bytes. I tried the "detect" to see exactly what it is he was giving me. If it's already UTF8, then I'm not sure what that website is convert it to.
import chardet
byte_string = b"\x61\x62\x63"
decoded_string = byte_string.decode("utf8")
print(decoded_string)
sourceText = "Al BaÅ£á ̧©ah"
sourceTextBytes = bytes(sourceText, 'utf-8')
print(chardet.detect(sourceTextBytes))
decoded_string2 = sourceTextBytes.decode("utf")
print("Result2=", decoded_string2)
Output of above:
abc
{'encoding': 'utf-8', 'confidence': 0.9690625, 'language': ''}
Result2= Al BaÅ£á ̧©ah
The output is same as the input. I've tried ascic, utf8, etc... as the parms for the decode statement.
Part 2 - Here's another weird one that the solution below didn't work for (these are subdivison names from an ISO document a colleague purchased.)
GÉTMdÉTMbÉTMy
Someone gave me this string: "Al BaÅ£á ̧©ah" (it's probably an Arabic name), and asked me to translate it (and a list of other similar strings) in Python.
This website converts it to "Al Baţḩah" with the operation "UTF8 Decode". I'm trying to do the same in Python, but is what I tried and my results. Most of the examples took a series of unicode bytes. I tried the "detect" to see exactly what it is he was giving me. If it's already UTF8, then I'm not sure what that website is convert it to.
import chardet
byte_string = b"\x61\x62\x63"
decoded_string = byte_string.decode("utf8")
print(decoded_string)
sourceText = "Al BaÅ£á ̧©ah"
sourceTextBytes = bytes(sourceText, 'utf-8')
print(chardet.detect(sourceTextBytes))
decoded_string2 = sourceTextBytes.decode("utf")
print("Result2=", decoded_string2)
Output of above:
abc
{'encoding': 'utf-8', 'confidence': 0.9690625, 'language': ''}
Result2= Al BaÅ£á ̧©ah
The output is same as the input. I've tried ascic, utf8, etc... as the parms for the decode statement.
Part 2 - Here's another weird one that the solution below didn't work for (these are subdivison names)
GÉTMdÉTMbÉTMy
Someone gave me this string: "Al BaÅ£á ̧©ah" (it's probably an Arabic name), and asked me to translate it (and a list of other similar strings) in Python.
This website converts it to "Al Baţḩah" with the operation "UTF8 Decode". I'm trying to do the same in Python, but is what I tried and my results. Most of the examples took a series of unicode bytes. I tried the "detect" to see exactly what it is he was giving me. If it's already UTF8, then I'm not sure what that website is convert it to.
import chardet
byte_string = b"\x61\x62\x63"
decoded_string = byte_string.decode("utf8")
print(decoded_string)
sourceText = "Al BaÅ£á ̧©ah"
sourceTextBytes = bytes(sourceText, 'utf-8')
print(chardet.detect(sourceTextBytes))
decoded_string2 = sourceTextBytes.decode("utf")
print("Result2=", decoded_string2)
Output of above:
abc
{'encoding': 'utf-8', 'confidence': 0.9690625, 'language': ''}
Result2= Al BaÅ£á ̧©ah
The output is same as the input. I've tried ascic, utf8, etc... as the parms for the decode statement.
Part 2 - Here's another weird one that the solution below didn't work for (these are subdivison names from an ISO document a colleague purchased.)
GÉTMdÉTMbÉTMy
Someone gave me this string: "Al BaÅ£á ̧©ah" (it's probably an Arabic name), and asked me to translate it (and a list of other similar strings) in Python.
This website converts it to "Al Baţḩah" with the operation "UTF8 Decode". I'm trying to do the same in Python, but is what I tried and my results. Most of the examples took a series of unicode bytes. I tried the "detect" to see exactly what it is he was giving me. If it's already UTF8, then I'm not sure what that website is convert it to.
import chardet
byte_string = b"\x61\x62\x63"
decoded_string = byte_string.decode("utf8")
print(decoded_string)
sourceText = "Al BaÅ£á ̧©ah"
sourceTextBytes = bytes(sourceText, 'utf-8')
print(chardet.detect(sourceTextBytes))
decoded_string2 = sourceTextBytes.decode("utf")
print("Result2=", decoded_string2)
Output of above:
abc
{'encoding': 'utf-8', 'confidence': 0.9690625, 'language': ''}
Result2= Al BaÅ£á ̧©ah
The output is same as the input. I've tried ascic, utf8, etc... as the parms for the decode statement.
Part 2 - Here's another weird one that the solution below didn't work for (these are subdivison names)
GÉTMdÉTMbÉTMy
Someone gave me this string: "Al BaÅ£á ̧©ah" (it's probably an Arabic name), and asked me to translate it (and a list of other similar strings) in Python.
This website converts it to "Al Baţḩah" with the operation "UTF8 Decode". I'm trying to do the same in Python, but is what I tried and my results. Most of the examples took a series of unicode bytes. I tried the "detect" to see exactly what it is he was giving me. If it's already UTF8, then I'm not sure what that website is convert it to.
import chardet
byte_string = b"\x61\x62\x63"
decoded_string = byte_string.decode("utf8")
print(decoded_string)
sourceText = "Al BaÅ£á ̧©ah"
sourceTextBytes = bytes(sourceText, 'utf-8')
print(chardet.detect(sourceTextBytes))
decoded_string2 = sourceTextBytes.decode("utf")
print("Result2=", decoded_string2)
Output of above:
abc
{'encoding': 'utf-8', 'confidence': 0.9690625, 'language': ''}
Result2= Al BaÅ£á ̧©ah
The output is same as the input. I've tried ascic, utf8, etc... as the parms for the decode statement.
Someone gave me this string: "Al BaÅ£á ̧©ah" (it's probably an Arabic name), and asked me to translate it (and a list of other similar strings) in Python.
This website converts it to "Al Baţḩah" with the operation "UTF8 Decode". I'm trying to do the same in Python, but is what I tried and my results. Most of the examples took a series of unicode bytes. I tried the "detect" to see exactly what it is he was giving me. If it's already UTF8, then I'm not sure what that website is convert it to.
import chardet
byte_string = b"\x61\x62\x63"
decoded_string = byte_string.decode("utf8")
print(decoded_string)
sourceText = "Al BaÅ£á ̧©ah"
sourceTextBytes = bytes(sourceText, 'utf-8')
print(chardet.detect(sourceTextBytes))
decoded_string2 = sourceTextBytes.decode("utf")
print("Result2=", decoded_string2)
Output of above:
abc
{'encoding': 'utf-8', 'confidence': 0.9690625, 'language': ''}
Result2= Al BaÅ£á ̧©ah
The output is same as the input. I've tried ascic, utf8, etc... as the parms for the decode statement.
Part 2 - Here's another weird one that the solution below didn't work for (these are subdivison names)
GÉTMdÉTMbÉTMy
Python decode from a specific string
Someone gave me this string: "Al BaÅ£á ̧©ah" (it's probably an Arabic name), and asked me to translate it (and a list of other similar strings) in Python.
This website converts it to "Al Baţḩah" with the operation "UTF8 Decode". I'm trying to do the same in Python, but is what I tried and my results. Most of the examples took a series of unicode bytes. I tried the "detect" to see exactly what it is he was giving me. If it's already UTF8, then I'm not sure what that website is convert it to.
import chardet
byte_string = b"\x61\x62\x63"
decoded_string = byte_string.decode("utf8")
print(decoded_string)
sourceText = "Al BaÅ£á ̧©ah"
sourceTextBytes = bytes(sourceText, 'utf-8')
print(chardet.detect(sourceTextBytes))
decoded_string2 = sourceTextBytes.decode("utf")
print("Result2=", decoded_string2)
Output of above:
abc
{'encoding': 'utf-8', 'confidence': 0.9690625, 'language': ''}
Result2= Al BaÅ£á ̧©ah
The output is same as the input. I've tried ascic, utf8, etc... as the parms for the decode statement.