[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

What is the encoding of __file__?

anne.nospam01

1/7/2008 9:54:00 PM

Dear all,

can someone quickly tell me what the encoding of __file__ is? I can't
find it in the documentation.

BTW, I'm using Python 2.5.1 on WIndows XP and Vista.

Kind regards,
Sebastian
3 Answers

Martin v. Loewis

1/7/2008 10:06:00 PM

0

> can someone quickly tell me what the encoding of __file__ is? I can't
> find it in the documentation.
>
> BTW, I'm using Python 2.5.1 on WIndows XP and Vista.

It's platform-specific - the same encoding that is used for file names
(i.e. sys.getfilesystemencoding()). On Windows, it will be "mbcs", which
in turn is installation-specific - on Western European/US installations,
it's "windows-1252".

Regards,
Martin

anne.nospam01

1/7/2008 10:30:00 PM

0

On 7 Jan., 23:06, "Martin v. Löwis" <mar...@v.loewis.de> wrote:
> > can someone quickly tell me what the encoding of __file__ is? I can't
> > find it in the documentation.
>
> > BTW, I'm using Python 2.5.1 on WIndows XP and Vista.
>
> It's platform-specific - the same encoding that is used for file names
> (i.e. sys.getfilesystemencoding()). On Windows, it will be "mbcs", which
> in turn is installation-specific - on Western European/US installations,
> it's "windows-1252".

Thanks, I'll then use sys.getfilesystemencoding() to decode _file__
and re-encode into utf-8, which is the default encoding of all strings
in our software, as we deal a bit with Chinese terms.

Windows-1252 on my box. I just created a directory containing Chinese
characters (on Vista), and whoa, files opened with IDLE are empty,
import doesn't find modules in that directory. Of course Windows-1252
can't encode these ...

But I understand that Python 3 will clean this up?

Kind regards,
Sebastian

Martin v. Loewis

1/7/2008 11:03:00 PM

0

> Thanks, I'll then use sys.getfilesystemencoding() to decode _file__
> and re-encode into utf-8, which is the default encoding of all strings
> in our software, as we deal a bit with Chinese terms.
>
> Windows-1252 on my box. I just created a directory containing Chinese
> characters (on Vista), and whoa, files opened with IDLE are empty,
> import doesn't find modules in that directory. Of course Windows-1252
> can't encode these ...
>
> But I understand that Python 3 will clean this up?

In theory, yes. The current implementation doesn't.

Contributions are welcome.

Regards,
Martin