5

I wrote a program to give me the value of the 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)

But when I go to run it I get

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

What do I need to do to fix it? It worked when I was running it on my pi but I can't seem to get it to run on my laptop. My laptop is running Python 2.7.5

AceFuzion
  • 51
  • 1
  • 1
  • 2
  • I changed all the `“` to `"` and the `‘` to `'` and got `Traceback (most recent call last): File "MegaDogeCoinTicker.py", line 29, in rawHTML = get_HTML() File "MegaDogeCoinTicker.py", line 6, in get_HTML response = urllib.request.urlopen('http://www.dogepay.com') NameError: global name 'urllib' is not defined` – AceFuzion Aug 07 '14 at 19:41
  • 1
    ...which is a completely different error, meaning your question has been solved. – Charles Duffy Aug 07 '14 at 19:46

3 Answers3

16

In addition to not using non-ascii quotation marks, you should add to the top line of your code:

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

details

Community
  • 1
  • 1
philshem
  • 24,761
  • 8
  • 61
  • 127
9

You should use standard ASCII quotes:

index = rawHTML.find("CCFF00")

rather than:

index = rawHTML.find(“CCFF00”)
mgilson
  • 300,191
  • 65
  • 633
  • 696
  • 5
    Which is to suggest, choose a better editor for whatever you're writing your python code in. – g.d.d.c Aug 07 '14 at 19:32
  • 1
    @g.d.d.c -- Yep, it's usually a good idea to use an editor which is designed for writing code :-) – mgilson Aug 07 '14 at 19:34
  • 1
    @g.d.d.c this has the smell of MS Word all over it. – Mark Ransom Aug 07 '14 at 19:35
  • 1
    I changed all the `“` to `"` and the `‘` to `'` and got `Traceback (most recent call last): File "MegaDogeCoinTicker.py", line 29, in rawHTML = get_HTML() File "MegaDogeCoinTicker.py", line 6, in get_HTML response = urllib.request.urlopen('http://www.dogepay.com') NameError: global name 'urllib' is not defined` – AceFuzion Aug 07 '14 at 19:42
  • 1
    @AceFuzion, well, getting that error means this one should be fixed. Also, if you read your code, its cause should be completely obvious. – Charles Duffy Aug 07 '14 at 19:47
0

I was running into this and it turns out that my copy/paste from my browser copied what looked like a plain dash character but wasn't. Maybe something simple to look out for.

Christy
  • 239
  • 2
  • 7