diff --git a/spyder/utils/encoding.py b/spyder/utils/encoding.py index 81eb583a9c5..2e6b270c8bf 100644 --- a/spyder/utils/encoding.py +++ b/spyder/utils/encoding.py @@ -171,6 +171,13 @@ def encode(text, orig_coding): if orig_coding == 'utf-8-bom': return BOM_UTF8 + text.encode("utf-8"), 'utf-8-bom' + # Try saving with original encoding + if orig_coding: + try: + return text.encode(orig_coding), orig_coding + except UnicodeError: + pass + # Try declared coding spec coding = get_coding(text) if coding: