[Tutor] syntax error when attempting simple urllib.request.urlopen item

Lukas Nemec lu.nemec at gmail.com
Wed Jul 10 15:35:38 CEST 2013


> On 07/09/2013 04:00 PM, Paul Smith wrote:
>> Tutor-
>>
>> Ok newbie to coding here attempting to build controlled web scraper and
>> have followed several books-tutorials and am failing at step one.
>>
>> This is the 3.3.1 code I am trying to run..
>> ===
>> import urllib.request
>>
>> htmltext = urllib.request.urlopen("http://google.com").read
>>
>> print htmltext
>> ===
>> Other version...
>> ===
>> #try py url open 7
>>
>> import urllib.request
>> res = urllib.request.urlopen('http://python.org/')
>> html = res.read()
>> print = html
>> close res
>> input = ("Press enter to exit")
>> ===
>>
>> so when I run what I think is proper 3.3.1 python code it hangs up with
>> syntax error with the idle shell red highlighting the last print 
>> reference
>> i.e. "htmltext"  or "html".
>>
>> What is this humble newbie not getting?
>
In the second example you have print = html ..
you can't do that, print is a build in function, so try print(html)

you should consider using some IDE that will alert you to these simple 
mistakes
you can try NinjaIDE, Eclipse (PyDev), or Vim with pylint plugin

Lukas


More information about the Tutor mailing list