COSC 2P91
Let’s Python Some More! Week 8a
Brock University
Brock University (Week 8a) Let’s Python Some More! 1 / 16
COSC 2P91 Lets Python Some More! Week 8a Brock University Brock - - PowerPoint PPT Presentation
COSC 2P91 Lets Python Some More! Week 8a Brock University Brock University (Week 8a) Lets Python Some More! 1 / 16 Remember Python? Lets all remember Python for a moment Weve gotten a basic look at the syntax (primarily in the
Brock University (Week 8a) Let’s Python Some More! 1 / 16
◮ Achieved via modules, instead of translation units
Brock University (Week 8a) Let’s Python Some More! 2 / 16
◮ Technically, you could load your file directly from the interactive
Brock University (Week 8a) Let’s Python Some More! 3 / 16
Brock University (Week 8a) Let’s Python Some More! 4 / 16
◮ Though not strictly necessary, try to have all of your function
◮ It can be hard to read if you have code, function declaration, code,
Brock University (Week 8a) Let’s Python Some More! 5 / 16
Brock University (Week 8a) Let’s Python Some More! 6 / 16
Brock University (Week 8a) Let’s Python Some More! 7 / 16
Brock University (Week 8a) Let’s Python Some More! 8 / 16
◮ It rhymes with lekshmample mime! Brock University (Week 8a) Let’s Python Some More! 9 / 16
◮ generator expressions have the same syntax as list comprehensions, and
◮ xrange is actually a special case of a generator
Brock University (Week 8a) Let’s Python Some More! 10 / 16
◮ (more accurately, they’re shorthand for creating generators)
◮ I assume we know what these words mean, and thus no explanation is
Brock University (Week 8a) Let’s Python Some More! 11 / 16
◮ import slide11c ⋆ Seriously, don’t forget about the help function here! ⋆ Also, dir is useful! ◮ from slide11c import * Brock University (Week 8a) Let’s Python Some More! 12 / 16
Brock University (Week 8a) Let’s Python Some More! 13 / 16
◮ We need to be more clever in how we write the module in the first place ◮ There are some properties that each module has innately ⋆ Let’s try using dir() right now on a fresh invocation of the interpreter ⋆ Notice the
⋆ Try importing the example, and checking its
◮ Basically, if a script checks if its name is
Brock University (Week 8a) Let’s Python Some More! 14 / 16
Brock University (Week 8a) Let’s Python Some More! 15 / 16
Brock University (Week 8a) Let’s Python Some More! 16 / 16