Giter VIP home page Giter VIP logo

practical-python's People

Contributors

advishnuprasad avatar alexdelorenzo avatar altvec avatar bid0uille avatar caticoa3 avatar chadbean avatar dabeaz avatar davideag avatar dlitvakb avatar droculus90 avatar echasnovski avatar encukou avatar gabrielsroka avatar ghreat avatar lzblack avatar mfsjmenger avatar paulliwali avatar pauloxnet avatar philodavies avatar qdoer avatar tburrows13 avatar tweakimp avatar vpoulailleau avatar zyuhel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

practical-python's Issues

CTA 22 Bus Hours

It seems that route 22 does not have.24 hours service. If you try the Exercise 1.4 when the service is not in operation nothing gets printed:

>>> u = urllib.request.urlopen('http://ctabustracker.com/bustime/map/getStopPredictions.jsp?stop=14791&route=22')
>>> doc = parse(u)
>>> for pt in doc.findall('.//pt'):
...     print(pt.text)                                                          ... 
>>> 

This might be worrying for someone who is new to Python. After viewing the xml via a browser, I was able to work out why there was no output.

>>> for pt in doc.findall('.//noPredictionMessage'):                            ...     print(pt.text)
... 
No arrival times

I did manage to get an arrival time using route 5 & stop 12023 but that seems to be a night only service. (I have never visited Chicago).

>>> u = urllib.request.urlopen('http://ctabustracker.com/bustime/map/getStopPredictions.jsp?stop=12023&route=5')
>>> doc = parse(u)
>>> for pt in doc.findall('.//pt'):                                             ...     print(pt.text)                                                          ... 
APPROACHING
24 MIN

Perhaps a word of warning could be given along the lines of

"If you try this in the middle of the night or live overseas, there may be no buses running on route 22. If you don't see a list of pending arrivals, try to check for bus route 5 at stop 12023."

Exercise 1.9: inclusive or exclusive range

From the description it is not clear if the extra payment start and/or end month should be included in the range. The exercise asks for "4 years starting in year 5", the code shows an exclusive range [60, 108], but the solution uses an inclusive range with ">=" and "<=" which results in 49 months.

Minor Typo in Numbers page

What a great resource
Minor typo here
Notes/01_Introduction/03_Numbers.md#converting-numbers

>>> b = '3.14159' # It also works with strings containing numbers
>>> float(b)
3.15159

3.15159

Exercise 1.7: You should get an answer of 966279.5999999957 not 966,279.6

# mortgage.py

principal = 500000.0
rate = 0.05
payment = 2684.11
total_paid = 0.0

while principal > 0:
    principal = principal * (1+rate/12) - payment
    total_paid = total_paid + payment

print('Total paid', total_paid)

Enter this program and run it. I get an answer of 966279.5999999957. Not 966,279.6.

I can get an anwer of 966,279.6 by following:

# Exercise 1.7


principal = 500000.0
rate = 0.05
payment = 2684.11
total_paid = 0.0

while principal > 0:
    principal = principal * (1+rate/12) - payment
    total_paid = total_paid + payment

print('Total paid', round(total_paid, 1))

Typo: *decoration”

In "5.2 Classes and Encapsulation" under "Decorator Syntax" you have
*decoration”

Return link to Welcome page

It would be nice if the course pages had a return link to the welcome page (https://dabeaz-course.github.io/practical-python/) that was a bit more obvious than the GitHub fork link at the bottom of the page.

The Welcome page includes some resource links (like this Issue Tracker) that should be a little easier to get to. One possible solution would be to make the 'Practical Python Programming' title on each instruction page an active link back to the welcome.

Just a thought, feel free to modify/discard....

'\N{FORALL}' in section 1.4 give unicode error

Under Macos and ubuntu '\N{FORALL}' gives a unicode error

>>> d = '\N{FORALL}'
  File "<stdin>", line 1
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 0-9: unknown Unicode character name

but '\N{FOR ALL}' works

>>> d = '\N{FOR ALL}'
>>> d
'∀'

Section 1.1: false statement about the REPL

Warning: It is never possible to paste more than one Python command (statements that appear after >>>) to the basic Python shell at a time. You have to paste each command one at a time.

This is false, at least on FreeBSD with xfce4-terminal. I've been using Python for 6 years and can't remember this ever being true.

Multiple statements on one line

In "5.2 Classes and Encapsulation" in subsection "Managed Attributes" you have:

class Stock:
def init(self, name, shares, price):
self.name = name self.set_shares(shares) self.price = price

I imagine those were intended to be on separate lines.

Chapter 1.6 File Management missing foo.txt might be confusing for new python users

Hi Dave,

just working through the Practical Python course in preparation for the Advanced Python Course in July.

In the chapter 1.6 right at the start you are showing an example of how to read a file:

f = open('foo.txt', 'rt') # Open for reading (text)

The file doesn't exist in the Work folder so an exception occurs that might be confusing for people.

I think there should be a example file. Or even better reverse the order of reading and writing to a file and let the people first write some text to a file "foo.txt" and let them read it in again afterwards.

Add percentage format in 2.3 Formatting

Not be confused with the C-style formatting.

I think it would be helpful to let the reader know that you can do this:

>>> a_third = 1/3
>>> f'{a_third:.2%}' 
'33.33%'

Chapter 2.2 Containers - Excercise 2.5: List of Dictionaries: Missing path

Hi Dave,
I've just found this tiny bug in the example below. As mentioned on more than one occasion it is assumed that our working directory is ./Work/ therefore the code below will raise a FileNotFoundError because of the missing path.

Exercise 2.5: List of Dictionaries
Take the function you wrote in Exercise 2.4 and modify to represent each stock in the portfolio with a dictionary instead of a tuple. In this dictionary use the field names of "name", "shares", and "price" to represent the different columns in the input file.

Experiment with this new function in the same manner as you did in Exercise 2.4.

>>> portfolio = read_portfolio('portfolio.csv')

results in:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "report.py", line 24, in read_portfolio
    with open(filename, 'rt') as f:
FileNotFoundError: [Errno 2] No such file or directory: 'portfolio.csv'

To fix this add the correct path to the file:

>> portfolio = read_portfolio('Data/portfolio.csv')

Script improvement in Chapter 3.1

Hello dabeaz,

when I took the course I had to modify the marked a part of the script to make it work (Chapter 3.1, last script at the bottom):

'prices.csv' --> 'Data/prices.csv'

image

Just a minor improvement to your awesome course.

Cheers,
vraez

self.dx += dx

This is incredibly minor, but in 4.1, there's an example class with a move method.

def move(self, dx, dy):
    self.dx += dx
    self.dy += dy

Since there is no dx or dy attributes and you wouldn't add a change in x to a change in x, I think this was supposed to be:

def move(self, dx, dy):
    self.x += dx
    self.y += dy

Awkwardly worded sentence

In "Exercise 2.16: Using the zip() function" the sentence near the end of the exercise "Modify the report.py program you wrote in Section 2.3 that it uses..." would read better as "Modify the report.py program you wrote in Section 2.3 so that it uses..."

Subject-verb disagreement

In list comprehensions section under "Historical Digression": "List comprehension come from..." should be "List comprehensions come..."

Section 1.2: sampled code for Looping and Indentation not consistent

In section 1.2 the following example is used for Looping and Indentation:

while num_bills * bill_thickness < sears_height:
    print(day, num_bills, num_bills * bill_thickness)
    day = day + 1
    num_bills = num_bills * 2

print('Number of days', days)

If the intention is to sample a portion of the previously shown solution, then the last line should say print('Number of days', day) to make it consistent.

`\Notes\02_Working_with_data\02_Containers.md` Error after code runs:

\Notes\02_Working_with_data\02_Containers.md

Error after code runs:

records = []  # Initial empty list

with open('Data/portfolio.csv', 'rt') as f:
    for line in f:
        row = line.split(',')
        records.append((row[0], int(row[1])), float(row[2]))

TypeError Traceback (most recent call last)
in
2
3 with open('Work/Data/portfolio.csv', 'rt') as f:
----> 4 for line in f[1:]:
5 row = line.split(',')
6 records.append((row[0], int(row[1])), float(row[2]))

TypeError: '_io.TextIOWrapper' object is not subscriptable

2.4 Sequences#zip wrong parameters

Wrong:

columns = ['name', 'shares', 'price']
values = ['GOOG', 100, 490.1 ]
pairs = zip(a, b)
# ('name','GOOG'), ('shares',100), ('price',490.1)

Correct:

columns = ['name', 'shares', 'price']
values = ['GOOG', 100, 490.1 ]
pairs = zip(columns, values)
# ('name','GOOG'), ('shares',100), ('price',490.1)

itemgetter instead of def/lambda

Hi

thanks for offering this course online. i've learned a ton!

on https://github.com/dabeaz-course/practical-python/blob/main/Notes/07_Advanced_Topics/02_Anonymous_function.md

this example:

def stock_name(s):
    return s['name']

portfolio.sort(key=stock_name)

can also be implemented using itemgetter:

from operator import itemgetter
portfolio.sort(key=itemgetter('name'))

see https://docs.python.org/3/howto/sorting.html#operator-module-functions
and https://docs.python.org/3/library/operator.html#operator.itemgetter

i know it kinda defeats the purpose of what you're trying to show, but it's an alternative to keep you from writing one-liners.

maybe include both?

"You may never use _ in a program."

Hi! This line from Section 1.2, Hello World about underscores bothered me a bit:

This is only true in the interactive mode. You never use _ in a program.

Is the latter part safe to say? Since the _ character can be used as a throwaway, right? Like if I want a list to contain 5 boolean values, I can do:

tracker = [True for _ in range(5)]

Maybe it can be worded as, "the underscore has a different purpose in non-interactive mode." Apologies if this is amended later on and I just haven't gotten to that part.

That aside, congratulations on this book. Loving it so far! Apologies too if I'm using GitHub incorrectly -- I'm kinda new to this.

"Home" link on Contents.md page gives 404 error

Anchor on GitHub.com page

The home page for the course, on GitHub.com, has the anchor Take me to the Course Already! and the following text:

Ok, ok. Point your browser HERE!

Where HERE links to the Contents.md page (part of the "blob" directory tree).

However, the Home link at the bottom of that page is generating a 404 Page Not Found error as it is not returning to the correct point in the "blob" directory tree.

The Markdown code for the link is:

[Home](..)

Perhaps it should be the following?

[Home](..\..)

Link to https://dabeaz-course.github.io/

I found the link to this GitHub repo on Hacker News. However, it was only in looking at Issue #1 that I realized that the repo is mirrored at https://dabeaz-course.github.io/practical-python/.

There is a link from the GitHub.io page to the GitHub.com repo, but there is no link, that I can see, from the GitHub repo going in the opposite direction. Did I miss something, perhaps?

The Contents page on GitHub.io has the correct Home link. I do not know how the repo and the GitHub.io pages are related, so I'm not sure if the issue mentioned above can be corrected without causing some negative impact.

Couple of typos in page 5.1 Dictionaries Revisited

Just some minor typos I found:

  1. Replace "a collection of names values" with "a collection of named values"
  2. Replace "A attribute search process" with "An attribute search process"
  3. In the code snippet 'Dicts and Objects', replace {'name' : 'GOOG','shares' : 100, 'price': 490.1 } with {'name' : 'GOOG', 'shares' : 100, 'price': 490.1 } (additional space).

Thanks, great work!

Minor suggestion: mention bytes strings in exercise 1.28?

In exercise 1.28 you're looking at a gzipped file of the same portfolio data file from the previous exercises. One can't just substitute in the gzip with command, though, since now you'll get byte strings back. I think it's worth adding a sentence clarifying this: IMO it's a bit unexpected for the reader since the compressed content is still a text file (and more reinforcement of the fact that byte strings and regular strings are different can only be a good thing.)

Typo in Datatypes markdown

Notes/02_Working_with_data/01_Datatypes.md has a typo for the price value in the third code block of Exercise 2.2. It says the price is 75 when it should be 32.2, as the shares value was updated to 75, not the price value.

Diff:
@@ -338,7 +338,7 @@ above. Change the number of shares to 75.

>>> d['shares'] = 75
>>> d
-{'name': 'AA', 'shares': 75, 'price': 75}
+{'name': 'AA', 'shares': 75, 'price': 32.2}
>>>

[Suggestion] On the Use of the Underscore in Programs

Chapter: https://dabeaz-course.github.io/practical-python/Notes/01_Introduction/02_Hello_world.html

At the end of section on Interactive Mode, it's stated about the underscore that "this is only true in the interactive mode. You never use _ in a program."

Perhaps the last sentence could be clarified to mean that underscores are not used to store the "previous values" (whatever that may mean in the context of programs), since _ may be used as a dummy variable.

"if" statements in lambda functions

Section 7.2 says No statements like if, while, etc. in lambda functions. While it's true that they don't handle full if-elif-else statements, it's possible (and often handy) to use ternary operators.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.