Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature_request(encoding): force UTF-8 for Windows users #59

Open
Kristinita opened this issue Aug 26, 2018 · 2 comments
Open

feature_request(encoding): force UTF-8 for Windows users #59

Kristinita opened this issue Aug 26, 2018 · 2 comments
Labels

Comments

@Kristinita
Copy link

1. Summary

In my opinion, UTF-8 should be the default encoding for Windows users. If developers of delegator.py don't want to do this, it would be nice to have an option for UTF-8.

2. Argumentation

I don't understand, why needs these lines for Windows users.

if sys.platform == 'win32':
    default_encoding = locale.getdefaultlocale()[1]
    if default_encoding is not None:
        encoding = default_encoding

More about locale.getdefaultlocale(). I have English Windows and Russian language for non-unicode programs. Python interpreter output:

>>> import locale
>>> locale.getdefaultlocale()
('en_US', 'cp1251')

I change my language for non-Unicode programs to English (United States) as recommend in this answer:

English default

I restart Windows → I open Python Interpreter again:

>>> import locale
>>> locale.getdefaultlocale()
('en_US', 'cp1252')

Not UTF-8 again. The example shows that locale.getdefaultlocale() can't set UTF-8 for Windows.

3. Example

  • SashaDelegator.py (in UTF-8):
import delegator

print(delegator.run('echo Саша Богиня!').out)

I run in console python SashaDelegator.py

4. Expected behavior

Саша Богиня!

5. Actual behavior

???? ??????!

This hack also doesn't help.

import _locale
import delegator

_locale._getdefaultlocale = (lambda *args: ['en_US', 'utf8'])

print(delegator.run('echo Саша Богиня!').out)

I get the same output.

And if I use hacks, I have problems with code quality tools.

6. Environment

  • Windows 10 Enterprise LTSB 64-bit EN
  • Python 3.7.0
  • delegator.py 0.1.0
  • PYTHONIOENCODING utf-8

Thanks.

@Kristinita
Copy link
Author

@nateprewitt , @kennethreitz, any ideas, how to fix it?

Thanks.

@danieldjewell
Copy link

For what it's worth, this sounds like a Python issue perhaps? The locale module is part of Python itself, of course (https://docs.python.org/3/library/locale.html) ...

Also, be aware that a lot of Windows -things- default to UTF-16... Also, check out Microsoft Terminal for a much improved CLI experience (https://github.com/microsoft/terminal)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants