Skip to content

Python programming sequence not fully updated for Python 3 #1885

@aschock1

Description

@aschock1

At least several lessons in the Python sequence aren't updated for Python 3. I'm trying to assign this sequence to a class (did so successfully in 2014 and 2016, so I really appreciate it!), but am starting a class this semester, and found that much of the sequence doesn't work with Python 3.

Lesson: Working with Text Files
OS: Mac
Version: 10.5.5
Python version: 3.8

Lesson calls to use the following text:
# file-output.py f = open('helloworld.txt','wb') f.write('hello world') f.close()

After trouble-shooting, I found that while this worked in Python 2.7, in which 'wb' writes bytes, in 3.0, the proper command is 'w'.

More serious is the issue with Downloading Pages with Python. Same system. In this case, the open-page.py doesn't work (and it's necessary for most of the further lessons in the sequence).

Here's the PH code

`# open-webpage.py

import urllib.request, urllib.error, urllib.parse

url = 'http://www.oldbaileyonline.org/browse.jsp?id=t17800628-33&div=t17800628-33'

response = urllib.request.urlopen(url)
webContent = response.read()

print(webContent[0:300])`

After trying various ways to get this to work, I contacted one of the authors, Bill Turkel, who found that the urllib module has been deprecated: [https://stackoverflow.com/questions/36781105/import-urllib-request-importerror-no-module-named-request?rq=1]

Other updates that would be good for these lessons:

  • Textwranger is now BB Edit
  • For Komodo edit, users need to right-click on the "Run" to get it to run (at least on Macs, double-click doesn't work)
  • oldbaileyonline.org might require https protocol for requests

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions