Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

 Python For Newbie

views
     
jzng89
post Jun 2 2023, 09:48 PM

Getting Started
**
Junior Member
95 posts

Joined: Nov 2007
From: Everywhere


QUOTE(FlierMate @ May 30 2023, 10:55 PM)
I got the same Python program that work in Linux (WSL) but not in Windows.

The error in Windows thrown by python3:

CODE
Traceback (most recent call last):
 File "C:\Users\BOO\Projects\xx\xx.py", line 309, in <module>
   xxFileLines = f.readlines()
                 ^^^^^^^^^^^^^
 File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1008.0_x64__qbz5n2kfra8p0\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 0x90 in position 5: character maps to <undefined>


The characters in question is Unicode characters, it cannot be processed in Windows. However, using python3 in Linux to read Unicode characters is OK wor.
*
Too little info but I'll take a guess, you're trying to read a txt file but Python is having issues converting the byte data into character data using cp1252 encoding.
Could be that byte 0x90 doesn't have any character value when using this CP1252 encoding, you could try to open the file using UTF-8 encoding instead.

Something like:

CODE

import io
f = io.open("YourFile.txt", mode="r", encoding="utf-8")
xxFileLines = f.readlines()


I don't work much with txt files when writing my code in Python so take this with a grain of salt.
FlierMate
post Jun 2 2023, 10:53 PM

On my way
****
Validating
543 posts

Joined: Nov 2020
QUOTE(jzng89 @ Jun 2 2023, 09:48 PM)
Too little info but I'll take a guess, you're trying to read a txt file but Python is having issues converting the byte data into character data using cp1252 encoding.
Could be that byte 0x90 doesn't have any character value when using this CP1252 encoding, you could try to open the file using UTF-8 encoding instead.

Something like:

CODE

import io
f = io.open("YourFile.txt", mode="r", encoding="utf-8")
xxFileLines = f.readlines()


I don't work much with txt files when writing my code in Python so take this with a grain of salt.
*
Your code can work.
user posted image

But it is someone's Python code cloned from GitHub, and as I said, the same code works in Linux, so I don't know what to suggest to the original author, maybe I will just open an Issue there.

Thanks pal!
flashang
post Jun 3 2023, 09:41 AM

Casual
***
Junior Member
355 posts

Joined: Aug 2021


QUOTE(FlierMate @ Jun 2 2023, 10:53 PM)
Your code can work.
user posted image

But it is someone's Python code cloned from GitHub, and as I said, the same code works in Linux, so I don't know what to suggest to the original author, maybe I will just open an Issue there.

Thanks pal!
*
May be the code you cloned from GitHub only handle ascii.
Since you have the code, why don't you enhance it ?

smile.gif


FlierMate
post Jun 3 2023, 02:17 PM

On my way
****
Validating
543 posts

Joined: Nov 2020
..............

This post has been edited by FlierMate: Jun 5 2023, 08:11 PM

 

Change to:
| Lo-Fi Version
0.0557sec    1.59    5 queries    GZIP Disabled
Time is now: 24th December 2025 - 10:39 PM