我写了一个程序给我这个巨型狗币的价值
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
我需要做什么来修复它?当我在圆周率上运行它时,它起作用了,但我似乎无法让它在我的笔记本上运行。我的笔记本电脑正在运行python 2.7.5
最佳答案
除了不使用非ascii引号外,还应在代码的顶行添加:
# -*- coding: utf-8 -*-
details