473,386 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Re: Where to locate existing standard encodings in python


On Nov 9, 2008, at 7:00 PM, News123 wrote:
Hi,

I was googling quite some time before finding the answer to my
question:
'what are the names for the encodings supported by python?'

I found the answer at http://python.active-venture.com/lib/
node127.html
Now my question:

Can I find the same info in the standard python doc or query python
with
a certain command to print out all existing codings?

Look under the heading "Standard Encodings":
http://docs.python.org/library/codecs.html

Note that both the page you found (which appears to be a copy of the
Python documentation) and the reference I provide say, "Neither the
list of aliases nor the list of languages is meant to be exhaustive".

I guess one reason for this is that different Python implementations
could choose to offer codecs for additional encodings.
Nov 10 '08 #1
3 2622

On Nov 11, 2008, at 9:10 AM, News123 wrote:
Hi Philip,

Your answer touches exaclty one point, which I was slightly afraid of:
- The list is not exhaustive
- python versions might have implemented different codecs.

This is why I wondered whether there's any way of querying python
for a
list of codecs it supports.
Try this:
Python 2.5.1 (r251:54863, Nov 17 2007, 21:19:53)
[GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>import encodings.aliases

encodings.aliases.aliases

"aliases" in the encodings.aliases module is a dict mapping alias
names (the dict keys) to encodings (the dict values). Thus, this will
give you the list of supported encodings:
>>set(encodings.aliases.aliases.values())

The encodings module isn't in the documentation (?!?); I found it when
looking through the Python source code. For that reason I can't say
more about how it works. You may want to experiment to see if
encodings added via codecs.register() show up in the
encodings.aliases.aliases dict.
Have fun
Philip
>
Philip Semanchuk wrote:
>>
On Nov 9, 2008, at 7:00 PM, News123 wrote:
>>Hi,

I was googling quite some time before finding the answer to my
question:
'what are the names for the encodings supported by python?'

I found the answer at http://python.active-venture.com/lib/node127.html
Now my question:

Can I find the same info in the standard python doc or query
python with
a certain command to print out all existing codings?


Look under the heading "Standard Encodings":
http://docs.python.org/library/codecs.html

Note that both the page you found (which appears to be a copy of the
Python documentation) and the reference I provide say, "Neither the
list
of aliases nor the list of languages is meant to be exhaustive".

I guess one reason for this is that different Python implementations
could choose to offer codecs for additional encodings.
--
http://mail.python.org/mailman/listinfo/python-list
Nov 11 '08 #2

On Nov 11, 2008, at 1:08 PM, News123 wrote:
Hi Philip,

Thanks for your answer:
The fact, that a module 'encodings' exists was new to me.
We both learned something new today. =)

encodings.aliases.aliases has however one problem.
It helps to locate all encoding aliases, but it won't find entries for
which no aliases exist:
Ooops, I hadn't thought about that.

What gives me a list of quite some encodings on my host is the shell
command
ls /usr/lib/python2.5/encodings | sed -n 's/\.py$//p' | sort
(soma false hits, bit this is fine for me purposes)

I don't know if really all encodings are represented with a .py file
and
if all encodigns have to be in this directory, but it's a start.
Using shell commands is not that pythonic:

I could try to rewrite this in python by
1.) determine from which directory encodings was imported and
then using the glob module to list all .py files located there.
Yes, I'd thought about this but I agree with you that it seems
unpythonic and fragile. Unfortunately I can't think of anything better
at this point.

Good luck
Philip

>
Philip Semanchuk wrote:
>>
On Nov 11, 2008, at 9:10 AM, News123 wrote:
>>Hi Philip,

Your answer touches exaclty one point, which I was slightly afraid
of:
- The list is not exhaustive
- python versions might have implemented different codecs.

This is why I wondered whether there's any way of querying python
for a
list of codecs it supports.

Try this:
Python 2.5.1 (r251:54863, Nov 17 2007, 21:19:53)
[GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin
Type "help", "copyright", "credits" or "license" for more
information.
>>>>import encodings.aliases
>
encodings.aliases.aliases


"aliases" in the encodings.aliases module is a dict mapping alias
names
(the dict keys) to encodings (the dict values). Thus, this will
give you
the list of supported encodings:
>>>>set(encodings.aliases.aliases.values())


The encodings module isn't in the documentation (?!?); I found it
when
looking through the Python source code. For that reason I can't say
more
about how it works. You may want to experiment to see if encodings
added
via codecs.register() show up in the encodings.aliases.aliases dict.
Have fun
Philip
>>>
Philip Semanchuk wrote:

On Nov 9, 2008, at 7:00 PM, News123 wrote:

Hi,
>
I was googling quite some time before finding the answer to my
question:
'what are the names for the encodings supported by python?'
>
I found the answer at http://python.active-venture.com/lib/node127.html
>
>
Now my question:
>
Can I find the same info in the standard python doc or query
python
with
a certain command to print out all existing codings?
Look under the heading "Standard Encodings":
http://docs.python.org/library/codecs.html

Note that both the page you found (which appears to be a copy of
the
Python documentation) and the reference I provide say, "Neither
the list
of aliases nor the list of languages is meant to be exhaustive".

I guess one reason for this is that different Python
implementations
could choose to offer codecs for additional encodings.
--
http://mail.python.org/mailman/listinfo/python-list
--
http://mail.python.org/mailman/listinfo/python-list
Nov 11 '08 #3
On Nov 11, 11:19 am, Philip Semanchuk <phi...@semanchuk.comwrote:
On Nov 11, 2008, at 1:08 PM, News123 wrote:
Hi Philip,
Thanks for your answer:
The fact, that a module 'encodings' exists was new to me.

We both learned something new today. =)
encodings.aliases.aliases has however one problem.
It helps to locate all encoding aliases, but it won't find entries for
which no aliases exist:

Ooops, I hadn't thought about that.
What gives me a list of quite some encodings on my host is the shell
command
ls /usr/lib/python2.5/encodings | sed -n 's/\.py$//p' | sort
(soma false hits, bit this is fine for me purposes)
I don't know if really all encodings are represented with a .py file
and
if all encodigns have to be in this directory, but it's a start.
Using shell commands is not that pythonic:
I could try to rewrite this in python by
1.) determine from which directory encodings was imported and
then using the glob module to list all .py files located there.

Yes, I'd thought about this but I agree with you that it seems
unpythonic and fragile. Unfortunately I can't think of anything better
at this point.

Good luck
Philip
....snip...

If it's of any help, in a post on 2007-07-22 by Peter Otten,
(though I can't get a url for it at the moment) he took the
same approach. From a saved copy of that post:

import encodings
import os
import glob

def encodings_from_modulenames():
ef = os.path.dirname(encodings.__file__)
for fn in glob.glob(os.path.join(ef, "*.py")):
fn = os.path.basename(fn)
yield os.path.splitext(fn)[0]
Nov 11 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Marko Faldix | last post by:
Hello, with Python 2.3 I can write umlauts (a,o,u umlaut) to a file with this piece of code: import codecs f = codecs.open("klotentest.txt", "w", "latin-1") print >>f, unicode("My umlauts...
27
by: John Roth | last post by:
PEP 263 is marked finished in the PEP index, however I haven't seen the specified Phase 2 in the list of changes for 2.4 which is when I expected it. Did phase 2 get cancelled, or is it just not...
5
by: F. GEIGER | last post by:
I'm on WinXP, Python 2.3. I don't have problems with umlauts (ä, ö, ü and their uppercase instances) in my wxPython-GUIs, when displayed as static texts. But when filling controls with text...
0
by: Quentin Crain | last post by:
Hello All: I am being told by my systems people that the load on the NFS servers is nasty. Our python installs are up on NFS. Also, on a bureaucratic note, I have very little input/control into...
0
by: packrat | last post by:
I am attempting to build a Bugzilla server on OS X. All of this is new to me, working with the Perl, MySQL, and Bugzilla, so I have been banging my head often. Software error: When I run the...
8
by: M Jared Finder | last post by:
I'm confused. XML looks to be extremely simple to read and write (so simple that I feel confidant I could program serialization and deserailization from a DOM document in an about an hour), yet I...
10
by: Bugs | last post by:
I believe I read in a relatively recent thread that the reason python24.dll is so large compared to previous releases is that all the language encodings are linked into the library? Are there...
0
by: henk-jan ebbers | last post by:
Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.9 Precedence: list List-Id: General discussion...
0
by: Mark Tolonen | last post by:
"News123" <news123@free.frwrote in message news:491779b1$0$19313$426a74cc@news.free.fr... The first hit from googling "site:python.org encodings":...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.