Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #80759 > unrolled thread
| Started by | satishmlmlml@gmail.com |
|---|---|
| First post | 2014-11-14 03:57 -0800 |
| Last post | 2014-11-14 07:30 -0500 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.python
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 308: character maps to <undefined> satishmlmlml@gmail.com - 2014-11-14 03:57 -0800
Re: UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 308: character maps to <undefined> Joel Goldstick <joel.goldstick@gmail.com> - 2014-11-14 07:30 -0500
| From | satishmlmlml@gmail.com |
|---|---|
| Date | 2014-11-14 03:57 -0800 |
| Subject | UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 308: character maps to <undefined> |
| Message-ID | <0a5917ca-70f3-4297-9e98-e8ed0556ee22@googlegroups.com> |
For 'mimetypes' in the code given below, python is giving the following error. Kindly help.
>>> import os
>>> matches = []
>>> for (dirname, dirshere, fileshere) in os.walk(r'C:\Python34'):
for filename in fileshere:
if filename.endswith('.py'):
pathname = os.path.join(dirname, filename)
if 'mimetypes' in open(pathname).read():
matches.append(pathname)
Traceback (most recent call last):
File "<pyshell#165>", line 5, in <module>
if 'mimetypes' in open(pathname).read():
File "C:\Python34\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 308: character maps to <undefined>
[toc] | [next] | [standalone]
| From | Joel Goldstick <joel.goldstick@gmail.com> |
|---|---|
| Date | 2014-11-14 07:30 -0500 |
| Message-ID | <mailman.15818.1415968687.18130.python-list@python.org> |
| In reply to | #80759 |
On Fri, Nov 14, 2014 at 6:57 AM, <satishmlmlml@gmail.com> wrote:
> For 'mimetypes' in the code given below, python is giving the following error. Kindly help.
>
>>>> import os
>>>> matches = []
>>>> for (dirname, dirshere, fileshere) in os.walk(r'C:\Python34'):
> for filename in fileshere:
> if filename.endswith('.py'):
> pathname = os.path.join(dirname, filename)
> if 'mimetypes' in open(pathname).read():
> matches.append(pathname)
>
>
> Traceback (most recent call last):
> File "<pyshell#165>", line 5, in <module>
> if 'mimetypes' in open(pathname).read():
> File "C:\Python34\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 308: character maps to <undefined>
You should understand encodings. There is lots of literature on the
web about unicode and python. In your case, the fact that you are
reading a file called cp1252.py and your code is raising a
UnicodeDecodeError should be a clue
> --
> https://mail.python.org/mailman/listinfo/python-list
--
Joel Goldstick
http://joelgoldstick.com
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web