语法错误:文件“...."中以 \xe0 开头的非 UTF-8 代码;但没有声明编码 [英] Syntax Error: Non-UTF-8 code starting with \xe0 in file "...." but no encoding declared

查看:42
本文介绍了语法错误:文件“...."中以 \xe0 开头的非 UTF-8 代码;但没有声明编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

# -*- coding: <utf-8> -*-
import re
conversiontable = { 'ॐ' : 'oṁ', 'ऀ' : 'ṁ', 'ँ' : 'ṃ', 'ं' : 'ṃ', 'ः' : 'ḥ', 'अ' : 'a', 'आ' : 'ā', 'इ' : 'i', 'ई' : 'ī', 'उ' : 'u', 'ऊ' : 'ū', 'ऋ' : 'r̥', 'ॠ' : ' r̥̄', 'ऌ' : 'l̥', 'ॡ' : ' l̥̄', 'ऍ' : 'ê', 'ऎ' : 'e', 'ए' : 'e', 'ऐ' : 'ai', 'ऑ' : 'ô', 'ऒ' : 'o', 'ओ' : 'o', 'औ' : 'au', 'ा' : 'ā', 'ि' : 'i', 'ी' : 'ī', 'ु' : 'u', 'ू' : 'ū', 'ृ' : 'r̥', 'ॄ' : ' r̥̄', 'ॢ' : 'l̥', 'ॣ' : ' l̥̄', 'ॅ' : 'ê', 'े' : 'e', 'ै' : 'ai', 'ॉ' : 'ô', 'ो' : 'o', 'ौ' : 'au', 'क़' : 'q', 'क' : 'k', 'ख़' : 'x', 'ख' : 'kh', 'ग़' : 'ġ', 'ग' : 'g', 'ॻ' : 'g', 'घ' : 'gh', 'ङ' : 'ṅ', 'च' : 'c', 'छ' : 'ch', 'ज़' : 'z', 'ज' : 'j', 'ॼ' : 'j', 'झ' : 'jh', 'ञ' : 'ñ', 'ट' : 'ṭ', 'ठ' : 'ṭh', 'ड़' : 'ṛ', 'ड' : 'ḍ', 'ॸ' : 'ḍ', 'ॾ' : 'd', 'ढ़' : 'ṛh', 'ढ' : 'ḍh', 'ण' : 'ṇ', 'त' : 't', 'थ' : 'th', 'द' : 'd', 'ध' : 'dh', 'न' : 'n', 'प' : 'p', 'फ़' : 'f', 'फ' : 'ph', 'ब' : 'b', 'ॿ' : 'b', 'भ' : 'bh', 'म' : 'm', 'य' : 'y', 'र' : 'r', 'ल' : 'l', 'ळ' : 'ḷ', 'व' : 'v', 'श' : 'ś', 'ष' : 'ṣ', 'स' : 's', 'ह' : 'h', 'ऽ' : '\'', '्' : '', '़' : '', '०' : '0', '१' : '1', '२' : '2', '३' : '3', '४' : '4', '५' : '5', '६' : '6', '७' : '7', '८' : '8', '९' : '9', 'ꣳ' : 'ṁ', '।' : '.', '॥' : '..', ' ' : ' ', }
consonants = '\u0915-\u0939\u0958-\u095F\u0978-\u097C\u097E-\u097F' 
vowelsigns = '\u093E-\u094C\u093A-\u093B\u094E-\u094F\u0955-\u0957' 
nukta = '\u093C' 
virama = '\u094D' 
devanagarichars = '\u0900-\u097F\u1CD0-\u1CFF\uA8E0-\uA8FF'

我一直在尝试使用上述映射将文本从拉丁文音译为梵文.我正在使用 VS Code,它抛出了我编码错误非 UTF-8 代码以 \xe0 开头的文件"....";但没有声明编码".我尝试将 utf-8 编码行放在代码上方,但没有用.

I have been trying to the above mapping to transliterate text from Latin to Devanagari. I am using VS Code and it is throwing me encoding error "Non-UTF-8 code starting with \xe0 in file "...." but no encoding declared". I tried putting utf-8 encoding line above the code but that didn't work.

谁能解释一下为什么会发生这种情况,我应该怎么做才能纠正它?

Can anyone explain me why it is happening and what should I do to correct it?

推荐答案

代码行应该是:

# -*- coding: utf-8 -*-

或者,如果您使用 python3,它可以在没有编码声明的情况下工作,因为它默认为 UTF-8.

Or, if you use python3, it works without the coding declaration, as it is UTF-8 by default.

这篇关于语法错误:文件“...."中以 \xe0 开头的非 UTF-8 代码;但没有声明编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆