0

So my script is in the folder which contains cyrillic symbols in the path and the __file__

variabale returns "encoding error" instead of a real path.

Adding the following line doesnt help

# -*- coding: cp1252 -*-

What should I do?

Version of python 3.3

Vladimir
  • 601
  • 2
  • 7
  • 13
  • Could you please provide the part where you deal with `__file__` ? An exception is raised? Or `__file__` variable contents are equal to `encoding error` ? – alex_jordan Sep 03 '13 at 15:43
  • I am just trying to print it, thats all, like `print(__file__)` – Vladimir Sep 03 '13 at 15:45
  • Any particular reason to use `cp1252` and not the default `utf-8` encoding of that file? –  Sep 03 '13 at 15:47
  • The script name is in utf8, but the path to it contains cyrillic symols, the clients use the folders with their specific names. Also, if I print the globals() there is `'__file__': ''` – Vladimir Sep 03 '13 at 15:48
  • No exception is raised, the content of variable is equal to `` – Vladimir Sep 03 '13 at 15:53

1 Answers1

0

I'm not sure if this answers your question, but...

In python3 the __file__ holds the current running script and path as a str. *nix systems use binary for filenames and have no preference for a particular encoding. When you use __file__ the system will attempt to take the binary string and encode it into a string using the default encoding system. I'm wondering if maybe your filenames are in cp1252 and python is trying to interpret it as utf8.

Python may follow the convention outlined here when encoding __file__: http://docs.python.org/2/library/sys.html#sys.getfilesystemencoding

You didn't state what OS you're using, though...

Tim Tisdall
  • 9,914
  • 3
  • 52
  • 82