Skip to content

Conversation

@tbekolay
Copy link
Contributor

Note that this is a PR on the py3k branch.

I did a runthrough of the Python 3 lessons after merging @rgaiacs's PR to clean up any loose ends. After making these changes, the lesson runs properly for me in Python 3.

Often, these changes are just noticing when Python 3 gives different outputs than Python 2 and updating accordingly, and a few spots where we still had print statement (these were added after #142 was made).

One odd thing is that in Python 3, the list returned by glob isn't sorted. I'm not sure if this is also true in Python 2, but to be sure that the output is correct, I added sorted calls.

Another somewhat large change is that the exception classes are changed in Python 3; importantly, there's no longer a base IOError. Instead, the specific IOErrors are separated out. Updated that lesson accordingly.

Things I noticed but didn't change:

  1. I found many floats that truncated differently in the lessons (e.g., 126.5) that truncated differently in my Python 3 environment (e.g., 126.50000000000001). This might be something specific to my machine though, not necessarily Python 3?
  2. In 02-loop, the challenge "From 1 to N" mentions that range(3) produces [0, 1, 2]. In Python 3 it instead produces an object, which prints as range(0, 3). You can still iterate over it though, so it doesn't directly affect the challenge, but the pedant in me has a "well, actually" moment when I read the challenge.
  3. In Lesson 6, the difference in standard deviations before and after is exactly zero on my machine. I'm not sure if this is, again, a machine difference, or if it's a Python 3 difference.

Mostly these are just noticing when Python 3 gives different outputs
than Python 2 and updating accordingly, and a few spots where print
statements were missed (I think these print statements were added
after the PR was made).

One odd thing is that in Python 3, the list returned by `glob` isn't
sorted. I'm not sure if this is also true in Python 2, but to be sure
that the output is correct, I added `sorted` calls.

Another somewhat large change is that the exception classes are changed
in Python 3; importantly, there's no longer a base IOError. Instead,
the specific IOErrors are separated out.
Updated that lesson accordingly.

Things I noticed but didn't change:

1. I found many floats that truncated differently in the lessons
   (e.g., 126.5) that truncated differently in my Python 3 environment
   (e.g., 126.50000000000001). This might be something specific to my
   machine though, not necessarily Python 3?
2. In 02-loop, the challenge "From 1 to N" mentions that range(3)
   produces [0, 1, 2]. In Python 3 it instead produces an object,
   which prints as range(0, 3). You can still iterate over it though,
   so it doesn't directly affect the challenge, but the pedant in me
   has a "well, actually" moment when I read the challenge.
3. In Lesson 6, the difference in standard deviations before and after
   is exactly zero on my machine. I'm not sure if this is, again,
   a machine difference, or if it's a Python 3 difference.
@rgaiacs
Copy link
Contributor

rgaiacs commented Aug 29, 2015

@tbekolay Thanks for the pull request. Looks great to me.

In 02-loop, the challenge "From 1 to N" mentions that range(3) produces [0, 1, 2]. In Python 3 it instead produces an object, which prints as range(0, 3). You can still iterate over it though, so it doesn't directly affect the challenge, but the pedant in me has a "well, actually" moment when I read the challenge.

That is true. At the begin Python only had lists so range returned a list. Later was introduced generators to help improve Python performance. For backward compatibility, in Python 2 users have range that return a list and xrange that return a "generator". But in Python 3, xrange was renamed to range and if you need a list you need to write list(range(0, 3)).

If I made a mistake, please correct me. =)

@tbekolay
Copy link
Contributor Author

if you need a list you need to write list(range(0, 3))

Right yeah. Do you think it makes sense to include the list call in that challenge? Personally I think it makes things more complicated for little benefit, but we also don't want to mislead students.

@rgaiacs
Copy link
Contributor

rgaiacs commented Aug 29, 2015

if you need a list you need to write list(range(0, 3))

Right yeah. Do you think it makes sense to include the list call in that challenge?

My first thought is yes but I agree with you when you say

Personally I think it makes things more complicated for little benefit, but we also don't want to mislead students.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please modify to show glob.glob first (with items not sorted), then introduce sorted in a callout box with a note saying "you should only bother to sort if you really care, and you usually only really care as the last step of processing".

gvwilson pushed a commit that referenced this pull request Aug 31, 2015
Minor updates for Python 3 compatibility
@gvwilson gvwilson merged commit 9ef20e6 into py3k Aug 31, 2015
@tbekolay tbekolay deleted the py3k-runthrough branch February 11, 2016 11:23
zkamvar pushed a commit that referenced this pull request Apr 21, 2023
Minor updates for Python 3 compatibility
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants