繁体   English   中英

SyntaxError:非ASCII字符'\ xe2'

[英]SyntaxError: Non-ASCII character '\xe2'

我写了一个程序来给我Mega Doge Coin的价值

import time
import urllib2
from datetime import datetime

def get_HTML():
    response = urllib.request.urlopen('http://www.dogepay.com')
    html = response.read()
    return html

def get_Value(rawHTML):
    index = rawHTML.find(“CCFF00”)
    while(rawHTML[index] != “$”):
            index = index + 1
    index = index + 1
    value = “”
    while(rawHTML[index].isdigit() or rawHTML[index] == ‘.’):
            value = value + rawHML[index]
            index = index + 1
    return float(value)

def get_DateTime():
    now = datetime.now()
    return '%s/%s/%s %s:%s:%s' % (now.month, now.day, now.year, now.hour, 
                                  now.minute, now.second)

def print_Output(DogeCoinValue, TimeDate):
    print timeDate + “ $“ + str(dogeCoinValue)

while(True):
    rawHTML = get_HTML()
    dogeCoinValue = get_Value(rawHTML)
    timeDate = get_DateTime()
    print_Output(dogeCoinValue, timeDate)
    time.sleep(5)

但是当我去跑步时,我得到了

File "MegaDogeCoinTicker.py", line 11
SyntaxError: Non-ASCII character '\xe2' in file MegaDogeCoinTicker.py on line 
11, but no encoding declared; see http://www.python.org/peps/pep-0263.html 
for details

我需要做些什么来解决它? 当我在我的pi上运行它时,它工作,但我似乎无法让它在我的笔记本电脑上运行。 我的笔记本电脑正在运行Python 2.7.5

除了不使用非ascii引号外,您还应该添加到代码的顶行:

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

细节

您应该使用标准ASCII引号:

index = rawHTML.find("CCFF00")

而不是:

index = rawHTML.find(“CCFF00”)

我遇到了这个问题,事实证明我的浏览器中的复制/粘贴复制了看起来像一个简单的短划线字符,但事实并非如此。 也许一些简单的东西需要注意。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM