title
James Powell: So you want to be a Python expert? | PyData Seattle 2017

description
www.pydata.org PyData is an educational program of NumFOCUS, a 501(c)3 non-profit organization in the United States. PyData provides a forum for the international community of users and developers of data analysis tools to share ideas and learn from each other. The global PyData network promotes discussion of best practices, new approaches, and emerging technologies for data management, processing, analytics, and visualization. PyData communities approach data science using many languages, including (but not limited to) Python, Julia, and R. PyData conferences aim to be accessible and community-driven, with novice to advanced level presentations. PyData tutorials and talks bring attendees the latest project features along with cutting-edge use cases. 0:00 About PyData and being proficient in Python 4:09 Important features of Python and audience survey 7:40 Data model methods 10:14 __init__ method 11:15 __repr__ method 12:17 __add__ method 15:51 __len__ method 18:42 __call__ method 20:50 Metaclasses and the problem of writing safe library code 27:00 Contraints on the library code using assert 32:33 Compile-time vs run time executable code 34:42 Disassembling class code and using __build_class__ 40:26 Constraining library code with the metaclass pattern 47:22 Introducing decorators 49:07 Code inspection 57:36 Writing a timer function 59:42 Decorator syntactic sugar 1:03:00 Writing a ntimes decorator 1:06:32 Wrapping functions into class 1:10:51 Eager execution 1:14:02 __iter__ and __next__ methods 1:17:40 yield and the Generator syntax 1:20:35 Coroutines and interleaving 1:24:35 Context Managers 1:25:30 Setup and teardown of resources 1:28:38 Applying to SQL transactions 1:30:10 __enter__ and __exit__ methods 1:32:30 Links between generators and context managers 1:36:02 Refactoring the SQL query code 1:37:52 Wrapping up 1:40:04 Opinions on writing clear code in Python 1:48:18 Q&A S/o to https://github.com/mycaule for the video timestamps! Want to help add timestamps to our YouTube videos to help with discoverability? Find out more here: https://github.com/numfocus/YouTubeVideoTimestamps

detail
{'title': 'James Powell: So you want to be a Python expert? | PyData Seattle 2017', 'heatmap': [{'end': 484.563, 'start': 410.378, 'weight': 0.792}, {'end': 1377.141, 'start': 1165.621, 'weight': 0.838}, {'end': 2264.946, 'start': 2057.338, 'weight': 0.867}, {'end': 2536.255, 'start': 2396.745, 'weight': 0.709}, {'end': 3018.132, 'start': 2808.686, 'weight': 0.919}, {'end': 3637.299, 'start': 3556.381, 'weight': 0.925}, {'end': 3975.985, 'start': 3903.635, 'weight': 0.783}, {'end': 5141.246, 'start': 5064.953, 'weight': 1}, {'end': 5901.122, 'start': 5823.87, 'weight': 0.944}, {'end': 6845.274, 'start': 6782.138, 'weight': 0.761}], 'summary': 'Explores the journey to becoming a python expert, covering topics like python features, core mental models, python patterns, metaclasses, context managers, and protocol-oriented nature, emphasizing the importance of practical application over syntax knowledge.', 'chapters': [{'end': 1164.52, 'segs': [{'end': 36.757, 'src': 'embed', 'start': 0.73, 'weight': 0, 'content': [{'end': 1.55, 'text': 'Good morning, everyone.', 'start': 0.73, 'duration': 0.82}, {'end': 2.571, 'text': "I'm James Powell.", 'start': 1.73, 'duration': 0.841}, {'end': 8.295, 'text': "As the session chair mentioned, I've been doing PyData for a very long time.", 'start': 3.392, 'duration': 4.903}, {'end': 11.658, 'text': "I think this is my 27th, 28th PyData conference I've attended.", 'start': 8.335, 'duration': 3.323}, {'end': 17.342, 'text': "I believe this is the 50-something PyData talk I've given in the last four years.", 'start': 11.678, 'duration': 5.664}, {'end': 21.045, 'text': "I don't know that that makes me a Python expert.", 'start': 18.122, 'duration': 2.923}, {'end': 28.83, 'text': "I can tell you that we have a lot of material to cover, so I won't go very deep into my own introduction other than to tell you that,", 'start': 21.765, 'duration': 7.065}, {'end': 36.757, 'text': 'Even though I attend many PI Data events and I help out in organizing all of these, I do this in the capacity of a volunteer.', 'start': 31.115, 'duration': 5.642}], 'summary': 'James powell has attended 27-28 pydata conferences and given 50+ talks in 4 years.', 'duration': 36.027, 'max_score': 0.73, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt4730.jpg'}, {'end': 68.144, 'src': 'embed', 'start': 42.479, 'weight': 1, 'content': [{'end': 48.721, 'text': "So, if you're interested in running a PI Data in your own city or getting more involved with open source data science, please let me know,", 'start': 42.479, 'duration': 6.242}, {'end': 50.682, 'text': 'or let any of the organizers of this conference know.', 'start': 48.721, 'duration': 1.961}, {'end': 53.403, 'text': "There's always room for more volunteers.", 'start': 51.322, 'duration': 2.081}, {'end': 60.558, 'text': "For those of you who've had the fortune or misfortune of seeing any of the talks that I've given previously at PyData events,", 'start': 55.193, 'duration': 5.365}, {'end': 63.74, 'text': 'I often give talks about strange things that you can do with Python,', 'start': 60.558, 'duration': 3.182}, {'end': 68.144, 'text': 'like embed Python interpreters within themselves or add features to Python at runtime,', 'start': 63.74, 'duration': 4.404}], 'summary': 'Seeking volunteers for pi data in cities, open source data science. room for more volunteers.', 'duration': 25.665, 'max_score': 42.479, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt442479.jpg'}, {'end': 169.018, 'src': 'embed', 'start': 140.134, 'weight': 2, 'content': [{'end': 142.536, 'text': "a little bit of an understanding of what's available in the standard library.", 'start': 140.134, 'duration': 2.402}, {'end': 145.999, 'text': 'This talk, however, is focused on the next step.', 'start': 143.536, 'duration': 2.463}, {'end': 149.522, 'text': 'What does it take to be a little bit better than just effective?', 'start': 146.639, 'duration': 2.883}, {'end': 152.684, 'text': 'What does it take to be good at Python or an expert at Python??', 'start': 149.682, 'duration': 3.002}, {'end': 159.11, 'text': 'Now I could spend the next two hours telling you in very philosophical terms what that means.', 'start': 153.445, 'duration': 5.665}, {'end': 165.355, 'text': 'And I could tell you why Python experts do things in one way or the other.', 'start': 159.69, 'duration': 5.665}, {'end': 169.018, 'text': 'We could even go very deeply into some of the meaning behind the Zen of Python.', 'start': 165.655, 'duration': 3.363}], 'summary': 'Focus on advancing python skills beyond standard library knowledge.', 'duration': 28.884, 'max_score': 140.134, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt4140134.jpg'}, {'end': 296.011, 'src': 'embed', 'start': 255.307, 'weight': 3, 'content': [{'end': 263.093, 'text': 'and a couple of the core mental models for how you can think about them and how you can think about Python as a whole and wrap all of these together.', 'start': 255.307, 'duration': 7.786}, {'end': 268.778, 'text': "One thing that you'll notice is, in addition to, you can probably hear, I'm a little bit stuffy and a little bit sick.", 'start': 264.034, 'duration': 4.744}, {'end': 275.203, 'text': "that's only going to exaggerate my inability to remember the syntax or the documentation for basically anything.", 'start': 268.778, 'duration': 6.425}, {'end': 276.884, 'text': 'So you may see me stumble,', 'start': 275.663, 'duration': 1.221}, {'end': 285.888, 'text': "But part of this presentation is to see me stumble and to understand that in cases where you don't have the documentation memorized,", 'start': 277.685, 'duration': 8.203}, {'end': 287.688, 'text': 'or some of the corner cases memorized,', 'start': 285.888, 'duration': 1.8}, {'end': 293.91, 'text': 'what really is more important for all of these features is an understanding of what they are and what they mean,', 'start': 287.688, 'duration': 6.222}, {'end': 296.011, 'text': 'and not so much all of the implementation details.', 'start': 293.91, 'duration': 2.101}], 'summary': 'Exploring core mental models for python, emphasizing understanding over memorization.', 'duration': 40.704, 'max_score': 255.307, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt4255307.jpg'}, {'end': 369.076, 'src': 'embed', 'start': 341.658, 'weight': 5, 'content': [{'end': 346.9, 'text': 'How many people are already in the back of the room thinking I should be in the front of the room giving a talk myself?', 'start': 341.658, 'duration': 5.242}, {'end': 349.322, 'text': 'Maybe one person?', 'start': 348.501, 'duration': 0.821}, {'end': 350.542, 'text': 'maybe one person in the front.', 'start': 349.322, 'duration': 1.22}, {'end': 352.884, 'text': "Okay, maybe we'll have to show you something new.", 'start': 350.943, 'duration': 1.941}, {'end': 358.649, 'text': "When it comes to those of you who've seen Python, how many of you feel like you're pretty effective in Python?", 'start': 354.366, 'duration': 4.283}, {'end': 364.673, 'text': 'I can give you a simple problem you can write some functions, maybe even write a class or two, and you can solve the problem without too much sweat.', 'start': 358.689, 'duration': 5.984}, {'end': 365.854, 'text': 'Is that most of you?', 'start': 365.213, 'duration': 0.641}, {'end': 369.076, 'text': "How many of you are complete newbies and you're like?", 'start': 366.834, 'duration': 2.242}], 'summary': 'Speaker queries audience on python proficiency, prompting self-assessment.', 'duration': 27.418, 'max_score': 341.658, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt4341658.jpg'}, {'end': 484.563, 'src': 'heatmap', 'start': 410.378, 'weight': 0.792, 'content': [{'end': 414.964, 'text': "So what I'll talk about at the very beginning is something that we might call the data model.", 'start': 410.378, 'duration': 4.586}, {'end': 422.389, 'text': "Now what you'll see is, I have all of the materials for this prepared and memorized in my brain.", 'start': 415.284, 'duration': 7.105}, {'end': 426.531, 'text': 'And unfortunately, my brain is getting older and older as time goes on.', 'start': 423.27, 'duration': 3.261}, {'end': 429.731, 'text': "And so I've already forgotten exactly what I want to talk about.", 'start': 426.911, 'duration': 2.82}, {'end': 431.572, 'text': "And so you'll see a little bit of roughness here.", 'start': 430.012, 'duration': 1.56}, {'end': 439.054, 'text': 'But part of the purpose of this presentation is to present you with just the information that matters without a lot of the distracting details.', 'start': 431.992, 'duration': 7.062}, {'end': 443.475, 'text': 'And so I will actually rewrite all of my notes for this as we go.', 'start': 439.514, 'duration': 3.961}, {'end': 444.816, 'text': "It's going to be a little bit rough.", 'start': 443.495, 'duration': 1.321}, {'end': 455.861, 'text': "but hopefully it'll be an opportunity for us to focus just on what really matters and for us to put aside a lot of the associated implementation details and things which,", 'start': 445.356, 'duration': 10.505}, {'end': 460.984, 'text': "frankly, it matters when you care about them, but it's not part of that core lesson of understanding Python.", 'start': 455.861, 'duration': 5.123}, {'end': 464.145, 'text': 'I want to start off with something very simple.', 'start': 462.284, 'duration': 1.861}, {'end': 466.947, 'text': 'And you can see I created a directory called data model.', 'start': 464.966, 'duration': 1.981}, {'end': 469.888, 'text': "And I'll just create a simple file in here.", 'start': 468.767, 'duration': 1.121}, {'end': 473.71, 'text': 'I want to create a class.', 'start': 472.929, 'duration': 0.781}, {'end': 476.235, 'text': "And we're going to do all of this.", 'start': 475.294, 'duration': 0.941}, {'end': 480.479, 'text': 'Everything in this course will be, or everything in this session will be in Python 3.6.', 'start': 476.295, 'duration': 4.184}, {'end': 484.563, 'text': "It'll be in Python 3.6, just for my own convenience,", 'start': 480.479, 'duration': 4.084}], 'summary': 'Presentation focuses on data model, simplifying info without distracting details. python 3.6 used throughout.', 'duration': 74.185, 'max_score': 410.378, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt4410378.jpg'}, {'end': 466.947, 'src': 'embed', 'start': 445.356, 'weight': 6, 'content': [{'end': 455.861, 'text': "but hopefully it'll be an opportunity for us to focus just on what really matters and for us to put aside a lot of the associated implementation details and things which,", 'start': 445.356, 'duration': 10.505}, {'end': 460.984, 'text': "frankly, it matters when you care about them, but it's not part of that core lesson of understanding Python.", 'start': 455.861, 'duration': 5.123}, {'end': 464.145, 'text': 'I want to start off with something very simple.', 'start': 462.284, 'duration': 1.861}, {'end': 466.947, 'text': 'And you can see I created a directory called data model.', 'start': 464.966, 'duration': 1.981}], 'summary': 'The focus is on understanding python core lessons, starting with a simple data model directory.', 'duration': 21.591, 'max_score': 445.356, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt4445356.jpg'}, {'end': 548, 'src': 'embed', 'start': 510.322, 'weight': 7, 'content': [{'end': 511.102, 'text': 'I have some class.', 'start': 510.322, 'duration': 0.78}, {'end': 514.164, 'text': 'I want to do some kind of mathematical operation.', 'start': 511.562, 'duration': 2.602}, {'end': 518.885, 'text': 'I have some piece of software I write, and I have some class here that represents a polynomial.', 'start': 514.203, 'duration': 4.682}, {'end': 527.443, 'text': 'simple linear polynomial with various coefficients, and I want to represent it as a Python object.', 'start': 521.217, 'duration': 6.226}, {'end': 530.306, 'text': 'And so I start with some code that looks like this.', 'start': 528.104, 'duration': 2.202}, {'end': 533.308, 'text': "Class polynomial, doesn't have anything interesting in it.", 'start': 530.706, 'duration': 2.602}, {'end': 536.791, 'text': 'And I can create two polynomials very simply.', 'start': 533.969, 'duration': 2.822}, {'end': 548, 'text': 'And I might say p1 has coefficients one, two, and three.', 'start': 543.977, 'duration': 4.023}], 'summary': 'Creating a python class to represent a simple linear polynomial with coefficients 1, 2, and 3.', 'duration': 37.678, 'max_score': 510.322, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt4510322.jpg'}, {'end': 728.238, 'src': 'embed', 'start': 685.674, 'weight': 8, 'content': [{'end': 694.053, 'text': 'So what method do I implement up here? I have some method called repper.', 'start': 685.674, 'duration': 8.379}, {'end': 711.664, 'text': 'I have some method here that returns a string that gives me a printable representation of this class to the screen.', 'start': 698.756, 'duration': 12.908}, {'end': 717.668, 'text': "I'll make this very easy, like that.", 'start': 712.265, 'duration': 5.403}, {'end': 719.97, 'text': "I'll run my code again.", 'start': 719.189, 'duration': 0.781}, {'end': 723.273, 'text': "And we'll see, oh, there we go.", 'start': 721.311, 'duration': 1.962}, {'end': 724.674, 'text': 'Those are our two polynomials.', 'start': 723.673, 'duration': 1.001}, {'end': 726.296, 'text': 'Pretty straightforward.', 'start': 725.195, 'duration': 1.101}, {'end': 728.238, 'text': 'And we could make this print out a little bit prettier.', 'start': 726.376, 'duration': 1.862}], 'summary': "Implement 'repper' method to return printable class representation.", 'duration': 42.564, 'max_score': 685.674, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt4685674.jpg'}, {'end': 989.051, 'src': 'embed', 'start': 955.638, 'weight': 10, 'content': [{'end': 958.26, 'text': 'It gives you some notion of the size of an object.', 'start': 955.638, 'duration': 2.622}, {'end': 968.124, 'text': 'What would it make sense for the size of a polynomial to be? What might that notion be? Any thoughts? The degree, right? The highest degree.', 'start': 958.78, 'duration': 9.344}, {'end': 972.506, 'text': 'So we want to implement this notion of size on this polynomial.', 'start': 968.865, 'duration': 3.641}, {'end': 974.206, 'text': 'How do we actually implement it?', 'start': 972.926, 'duration': 1.28}, {'end': 976.507, 'text': "What's the name of the underscore function we have to implement?", 'start': 974.706, 'duration': 1.801}, {'end': 980.008, 'text': "The one hint is, there's usually a very close correspondence here.", 'start': 977.387, 'duration': 2.621}, {'end': 982.529, 'text': 'So what would it be here? Len.', 'start': 980.368, 'duration': 2.161}, {'end': 989.051, 'text': 'If we wanted the exact arguments and any of the caveats for how this needs to be implemented, we could look at documentation.', 'start': 983.889, 'duration': 5.162}], 'summary': 'Implement size notion for polynomials using degree and len function.', 'duration': 33.413, 'max_score': 955.638, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt4955638.jpg'}, {'end': 1069.231, 'src': 'embed', 'start': 1044.893, 'weight': 9, 'content': [{'end': 1053.725, 'text': "the representation of any Python object is typically whatever string we'd have to type at the console to create another instance of that same object,", 'start': 1044.893, 'duration': 8.832}, {'end': 1054.185, 'text': 'and so on.', 'start': 1053.725, 'duration': 0.46}, {'end': 1057.129, 'text': 'In each case, this protocol exists.', 'start': 1055.407, 'duration': 1.722}, {'end': 1060.133, 'text': 'There is some underscore method that implements that protocol.', 'start': 1057.69, 'duration': 2.443}, {'end': 1069.231, 'text': 'there is some top level function, like len or repper, or some top level syntax, like the plus sign or the multiplication sign,', 'start': 1061.127, 'duration': 8.104}], 'summary': 'Python object representation protocol exists with underscore method and top level functions.', 'duration': 24.338, 'max_score': 1044.893, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt41044893.jpg'}], 'start': 0.73, 'title': 'Python expertise and data model', 'summary': "Explores the journey to becoming a python expert, emphasizing the speaker's experience in pydata conferences and volunteer opportunities. it also discusses python features, core mental models, and the python data model, covering topics such as creating a simple polynomial class and implementing custom behavior on python objects.", 'chapters': [{'end': 199.869, 'start': 0.73, 'title': 'Becoming a python expert', 'summary': "Delves into the journey of becoming a python expert, discussing the speaker's extensive experience in pydata conferences, volunteer opportunities, and the core mental models required to be effective and excel in python.", 'duration': 199.139, 'highlights': ['The speaker has attended approximately 27th or 28th PyData conferences and given around 50 PyData talks in the last four years, showcasing extensive experience in this field. Quantifiable data: Number of conferences attended and talks given.', 'The speaker emphasizes the availability of volunteer opportunities with Num Focus and PyData, encouraging the audience to get more involved with open source data science. Key point: Emphasizing volunteer opportunities and involvement in open source data science.', 'To be effective in Python, it requires a certain understanding of core mental models, built-in data types, built-in functions, and the standard library. Key point: Core requirements to be effective in Python.', 'The talk focuses on the next step - what it takes to be good at Python or an expert at Python, delving into the metaphors in programming in Python. Key point: Shift in focus to becoming an expert in Python and delving into programming metaphors.']}, {'end': 398.779, 'start': 200.549, 'title': 'Python features and core mental models', 'summary': 'Discusses four features of python and the core mental models for conceptualizing them, emphasizing the importance of understanding over memorizing syntax and documentation.', 'duration': 198.23, 'highlights': ['The presentation emphasizes the importance of understanding the core mental models for Python features over memorizing syntax and documentation. The speaker criticizes the approach of focusing solely on the syntax and formal characteristics of Python features, advocating for a broader understanding of their implications for modeling core problems.', 'The speaker acknowledges his inability to remember syntax or documentation due to being a bit stuffy and sick, emphasizing the importance of understanding the features over memorizing details. The speaker recognizes his current inability to remember syntax or documentation due to being unwell, highlighting the significance of understanding the features rather than memorizing implementation details.', "The speaker conducts a survey of the audience, addressing their proficiency in Python and acknowledging the varying levels of expertise. The speaker conducts a survey to gauge the audience's proficiency in Python, addressing Microsoft employees, their interaction with Python, and their proficiency levels, acknowledging both experienced and novice individuals.", 'The speaker acknowledges the struggle of complete newbies in understanding Python but assures that core lessons will not be totally lost on them. The speaker recognizes the challenges faced by complete newbies in understanding Python but assures that the core lessons discussed will still hold value for them, emphasizing the universality of the lessons being imparted.']}, {'end': 856.525, 'start': 399.52, 'title': 'Understanding python data model', 'summary': "Covers the basics of python's data model, focusing on creating a simple polynomial class, initializing it using an init method, implementing a repper method for better representation, and adding polynomials using dunder methods, highlighting the importance of data model methods in python.", 'duration': 457.005, 'highlights': ["The chapter covers the basics of Python's data model The chapter begins with an introduction to Python's data model, emphasizing the importance of understanding the core concepts.", 'Implementing a simple polynomial class and initializing it using an init method The speaker demonstrates the creation of a simple polynomial class and emphasizes the necessity of an init method for more concise and efficient code.', 'Importance of implementing a repper method for better representation The significance of implementing a repper method for obtaining a more readable and informative representation of Python objects is highlighted.', 'Adding polynomials using dunder methods and the significance of data model methods The speaker explains the process of adding polynomials using dunder methods, emphasizing the importance of data model methods in Python and their role in implementing specific behaviors.']}, {'end': 1164.52, 'start': 857.642, 'title': 'Python data model and custom behavior', 'summary': 'Discusses the python data model and the common pattern of implementing custom behavior on python objects through the use of top-level functions and corresponding underscore functions, exemplified by protocols like len, addition, and representation, providing a means to define the behavior of objects in python.', 'duration': 306.878, 'highlights': ['The Python data model involves a common pattern of implementing custom behavior on Python objects by using top-level functions and corresponding underscore functions, such as protocols like len, addition, and representation. The Python data model emphasizes the pattern of implementing custom behavior on Python objects through top-level functions and corresponding underscore functions, exemplified by protocols like len, addition, and representation.', 'The pattern of implementing custom behavior involves a top level function or syntax and a corresponding underscore function, with the exact arguments for the underscore function determined by the documentation. The pattern of implementing custom behavior on Python objects involves a top level function or syntax and a corresponding underscore function, with the exact arguments for the underscore function determined by the documentation.', 'The size of a polynomial can be implemented using the len protocol, where the highest degree serves as the notion of size for the polynomial. The size of a polynomial can be implemented using the len protocol, with the highest degree serving as the notion of size for the polynomial.', 'The representation of any Python object is typically the string that would be typed at the console to create another instance of the same object, and this principal representation is given by the documentation. The representation of any Python object is typically the string that would be typed at the console to create another instance of the same object, and this principal representation is given by the documentation.', 'The Python data model provides a means to implement protocols for different objects, with each protocol having some abstract meaning depending on the object itself. The Python data model provides a means to implement protocols for different objects, with each protocol having some abstract meaning depending on the object itself.']}], 'duration': 1163.79, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt4730.jpg', 'highlights': ['The speaker has attended approximately 27th or 28th PyData conferences and given around 50 PyData talks in the last four years, showcasing extensive experience in this field.', 'The speaker emphasizes the availability of volunteer opportunities with Num Focus and PyData, encouraging the audience to get more involved with open source data science.', 'The talk focuses on the next step - what it takes to be good at Python or an expert at Python, delving into the metaphors in programming in Python.', 'The speaker emphasizes the importance of understanding the core mental models for Python features over memorizing syntax and documentation.', 'The speaker acknowledges his inability to remember syntax or documentation due to being a bit stuffy and sick, emphasizing the importance of understanding the features over memorizing details.', 'The speaker conducts a survey of the audience, addressing their proficiency in Python and acknowledging the varying levels of expertise.', "The chapter covers the basics of Python's data model, emphasizing the importance of understanding the core concepts.", 'Implementing a simple polynomial class and initializing it using an init method.', 'Importance of implementing a repper method for better representation.', 'The Python data model involves a common pattern of implementing custom behavior on Python objects by using top-level functions and corresponding underscore functions, such as protocols like len, addition, and representation.', 'The size of a polynomial can be implemented using the len protocol, where the highest degree serves as the notion of size for the polynomial.', 'The representation of any Python object is typically the string that would be typed at the console to create another instance of the same object, and this principal representation is given by the documentation.']}, {'end': 1916.103, 'segs': [{'end': 1377.141, 'src': 'heatmap', 'start': 1165.621, 'weight': 0.838, 'content': [{'end': 1167.963, 'text': 'This is one of the core patterns that we see in Python.', 'start': 1165.621, 'duration': 2.342}, {'end': 1172.807, 'text': "This is probably one of the very first patterns that you'd see as a novice Python programmer.", 'start': 1168.343, 'duration': 4.464}, {'end': 1176.205, 'text': 'In fact, when you look at object orientation in Python,', 'start': 1173.743, 'duration': 2.462}, {'end': 1181.149, 'text': "there are three core patterns that you'd have to understand to really understand object orientation in Python.", 'start': 1176.205, 'duration': 4.944}, {'end': 1183.811, 'text': 'This is one of them, the protocol view of Python.', 'start': 1181.589, 'duration': 2.222}, {'end': 1190.776, 'text': 'The second one is the built-in inheritance protocol and how it works, where you go on a Python object to look for things.', 'start': 1184.291, 'duration': 6.485}, {'end': 1197.541, 'text': 'And the third one is some caveats around how object orientation in Python works.', 'start': 1192.057, 'duration': 5.484}, {'end': 1199.956, 'text': "That's where I wanted to start off with.", 'start': 1198.655, 'duration': 1.301}, {'end': 1204.86, 'text': 'And for those of you who are just kind of on that level of being effective in Python,', 'start': 1200.196, 'duration': 4.664}, {'end': 1207.442, 'text': 'these are the kind of patterns that I would encourage you to look out for.', 'start': 1204.86, 'duration': 2.582}, {'end': 1209.367, 'text': 'as you learn Python.', 'start': 1208.607, 'duration': 0.76}, {'end': 1214.609, 'text': 'I want to go much deeper than this and I want to jump into a very tricky metaphor,', 'start': 1210.227, 'duration': 4.382}, {'end': 1222.391, 'text': "using a feature which you may have heard of and you may have been warned against something you may have seen kind of along the margins when you're using some library.", 'start': 1214.609, 'duration': 7.782}, {'end': 1225.592, 'text': 'If you do anything with web programming and you use Django,', 'start': 1223.051, 'duration': 2.541}, {'end': 1230.573, 'text': 'you may have seen this in the ORM or you may have heard people whispering about this one feature.', 'start': 1225.592, 'duration': 4.981}, {'end': 1232.894, 'text': 'And I want to bring up this feature for you.', 'start': 1231.213, 'duration': 1.681}, {'end': 1236.075, 'text': 'I want to show you that it has a very clear and concise meaning.', 'start': 1233.074, 'duration': 3.001}, {'end': 1243.367, 'text': 'just to illustrate how powerful these mental models are for understanding Python itself and for driving expertise.', 'start': 1237.285, 'duration': 6.082}, {'end': 1246.207, 'text': "So let's shelve this for a second.", 'start': 1244.887, 'duration': 1.32}, {'end': 1250.669, 'text': "Let's shelve this idea of Python having a protocol-orientated data model.", 'start': 1246.407, 'duration': 4.262}, {'end': 1252.749, 'text': "And let's look into a new feature.", 'start': 1251.549, 'duration': 1.2}, {'end': 1258.611, 'text': "I'll create a new directory called metaclasses, and we'll talk about metaclasses for a bit.", 'start': 1254.43, 'duration': 4.181}, {'end': 1268.783, 'text': 'The gist of this tutorial is actually leading you towards three features which are far more common and far more interesting than metaclasses,', 'start': 1260.635, 'duration': 8.148}, {'end': 1271.226, 'text': 'namely decorators, generators and context managers.', 'start': 1268.783, 'duration': 2.443}, {'end': 1274.389, 'text': 'There is a reason I want to start you off with metaclasses.', 'start': 1271.907, 'duration': 2.482}, {'end': 1277.652, 'text': "It's a feature that everybody is warned against using.", 'start': 1275.11, 'duration': 2.542}, {'end': 1283.378, 'text': "They're told it's magical, it makes no sense, it's totally the most complicated thing in the world.", 'start': 1277.893, 'duration': 5.485}, {'end': 1289.973, 'text': 'When, in reality, it is the case of a feature where, if you understand what the feature is really about,', 'start': 1284.468, 'duration': 5.505}, {'end': 1293.636, 'text': 'it is very clear and very obvious for why and when you use it.', 'start': 1289.973, 'duration': 3.663}, {'end': 1301.362, 'text': "And it's something that you can kind of shelve away in your mind as, oh, this feature does this.", 'start': 1296.098, 'duration': 5.264}, {'end': 1302.723, 'text': 'This is why I want to use it.', 'start': 1301.622, 'duration': 1.101}, {'end': 1304.204, 'text': "I don't need to use it all the time.", 'start': 1303.083, 'duration': 1.121}, {'end': 1308.608, 'text': 'So let me show you what a metaclass or what metaclasses are really about.', 'start': 1305.265, 'duration': 3.343}, {'end': 1313.401, 'text': "And I'll show this to you for an example.", 'start': 1311.94, 'duration': 1.461}, {'end': 1316.824, 'text': "Now here's an opportunity for you to try something.", 'start': 1313.641, 'duration': 3.183}, {'end': 1324.51, 'text': "Because I think you'll really appreciate this example if you try, actually let me do this in a different way, library.py.", 'start': 1317.565, 'duration': 6.945}, {'end': 1330.915, 'text': 'So I have two files here, and I want you to actually try this.', 'start': 1328.333, 'duration': 2.582}, {'end': 1338.622, 'text': 'And I want you to remember, I want you to pretend that there are two groups working on some one piece of software.', 'start': 1331.516, 'duration': 7.106}, {'end': 1342.939, 'text': 'One group is a core infrastructure group, and they write library code.', 'start': 1339.978, 'duration': 2.961}, {'end': 1346.12, 'text': 'And the other group is a developer group, and they write user code.', 'start': 1343.539, 'duration': 2.581}, {'end': 1353.563, 'text': 'The developer group takes the library code somebody else wrote, and they use that library code to accomplish actual business objectives.', 'start': 1347.121, 'duration': 6.442}, {'end': 1362.487, 'text': 'The core infrastructure group gets paid a lot of money to accomplish no actual business objectives but to provide library software that the rest of us can use.', 'start': 1354.284, 'duration': 8.203}, {'end': 1372.158, 'text': "Isn't that the story of tech companies? Which team would you rather work on? Nobody has any opinion whatsoever.", 'start': 1363.287, 'duration': 8.871}, {'end': 1377.141, 'text': "I'd rather work on the user team, because I think that's where some of the more exciting work is,", 'start': 1372.638, 'duration': 4.503}], 'summary': 'Understanding core patterns in python and the power of mental models for expertise.', 'duration': 211.52, 'max_score': 1165.621, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt41165621.jpg'}, {'end': 1316.824, 'src': 'embed', 'start': 1268.783, 'weight': 0, 'content': [{'end': 1271.226, 'text': 'namely decorators, generators and context managers.', 'start': 1268.783, 'duration': 2.443}, {'end': 1274.389, 'text': 'There is a reason I want to start you off with metaclasses.', 'start': 1271.907, 'duration': 2.482}, {'end': 1277.652, 'text': "It's a feature that everybody is warned against using.", 'start': 1275.11, 'duration': 2.542}, {'end': 1283.378, 'text': "They're told it's magical, it makes no sense, it's totally the most complicated thing in the world.", 'start': 1277.893, 'duration': 5.485}, {'end': 1289.973, 'text': 'When, in reality, it is the case of a feature where, if you understand what the feature is really about,', 'start': 1284.468, 'duration': 5.505}, {'end': 1293.636, 'text': 'it is very clear and very obvious for why and when you use it.', 'start': 1289.973, 'duration': 3.663}, {'end': 1301.362, 'text': "And it's something that you can kind of shelve away in your mind as, oh, this feature does this.", 'start': 1296.098, 'duration': 5.264}, {'end': 1302.723, 'text': 'This is why I want to use it.', 'start': 1301.622, 'duration': 1.101}, {'end': 1304.204, 'text': "I don't need to use it all the time.", 'start': 1303.083, 'duration': 1.121}, {'end': 1308.608, 'text': 'So let me show you what a metaclass or what metaclasses are really about.', 'start': 1305.265, 'duration': 3.343}, {'end': 1313.401, 'text': "And I'll show this to you for an example.", 'start': 1311.94, 'duration': 1.461}, {'end': 1316.824, 'text': "Now here's an opportunity for you to try something.", 'start': 1313.641, 'duration': 3.183}], 'summary': 'Understanding metaclasses is important for clarity and selective use.', 'duration': 48.041, 'max_score': 1268.783, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt41268783.jpg'}, {'end': 1372.158, 'src': 'embed', 'start': 1343.539, 'weight': 3, 'content': [{'end': 1346.12, 'text': 'And the other group is a developer group, and they write user code.', 'start': 1343.539, 'duration': 2.581}, {'end': 1353.563, 'text': 'The developer group takes the library code somebody else wrote, and they use that library code to accomplish actual business objectives.', 'start': 1347.121, 'duration': 6.442}, {'end': 1362.487, 'text': 'The core infrastructure group gets paid a lot of money to accomplish no actual business objectives but to provide library software that the rest of us can use.', 'start': 1354.284, 'duration': 8.203}, {'end': 1372.158, 'text': "Isn't that the story of tech companies? Which team would you rather work on? Nobody has any opinion whatsoever.", 'start': 1363.287, 'duration': 8.871}], 'summary': 'Core infrastructure group provides library code for business objectives. tech company work dynamics.', 'duration': 28.619, 'max_score': 1343.539, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt41343539.jpg'}, {'end': 1400.417, 'src': 'embed', 'start': 1380.844, 'weight': 5, 'content': [{'end': 1392.391, 'text': "But some people like to be on the core infrastructure team because they think that the technical problems are often much more interesting than some particular business unit's problem around not getting data in the right format or who knows what.", 'start': 1380.844, 'duration': 11.547}, {'end': 1400.417, 'text': "Let's say that this library provides classes, and these classes are expected to be subclassed in the user code.", 'start': 1394.333, 'duration': 6.084}], 'summary': "Core infrastructure team finds technical problems more interesting than business unit's data issues.", 'duration': 19.573, 'max_score': 1380.844, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt41380844.jpg'}, {'end': 1510.727, 'src': 'embed', 'start': 1482.101, 'weight': 4, 'content': [{'end': 1493.255, 'text': 'Where could the code on the right hand side of the screen break? Very simply, where could this function break? If there is no foo method, exactly.', 'start': 1482.101, 'duration': 11.154}, {'end': 1505.503, 'text': 'What can you do in your code to make sure that, at least at the very minimum, if the person who writes the library code removes that foo method,', 'start': 1494.215, 'duration': 11.288}, {'end': 1510.727, 'text': 'your code fails not at runtime but at any point earlier than runtime?', 'start': 1505.503, 'duration': 5.224}], 'summary': 'Identify potential code breakage due to missing foo method and implement early failure detection.', 'duration': 28.626, 'max_score': 1482.101, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt41482101.jpg'}], 'start': 1165.621, 'title': 'Python patterns and library code usage', 'summary': 'Delves into three core python patterns, emphasizing the importance of metaclasses, decorators, generators, and context managers. it also discusses library code usage, constraints in software development, and strategies for enforcing constraints and preventing misuse.', 'chapters': [{'end': 1316.824, 'start': 1165.621, 'title': 'Understanding core python patterns', 'summary': 'Delves into the three core patterns in python, including the protocol view, built-in inheritance protocol, and object orientation caveats, and emphasizes the importance of understanding metaclasses, decorators, generators, and context managers as powerful mental models for python expertise.', 'duration': 151.203, 'highlights': ['The chapter discusses the three core patterns in Python: the protocol view, built-in inheritance protocol, and object orientation caveats. These core patterns are fundamental for understanding object orientation in Python and are essential for novice Python programmers.', 'The tutorial aims to emphasize the significance of understanding metaclasses, decorators, generators, and context managers as powerful mental models for Python expertise. The chapter encourages learners to grasp the importance of metaclasses, despite being warned against using them, and highlights the value of understanding these features for effective Python programming.', 'The chapter stresses the clarity and importance of understanding the metaclasses feature in Python, despite common warnings against it. It emphasizes that understanding the true purpose of metaclasses makes it clear and obvious when and why to use them, and that they can be stored as a mental model for future use.']}, {'end': 1916.103, 'start': 1317.565, 'title': 'Library code usage and constraints', 'summary': 'Discusses the usage of library code and constraints in software development, highlighting the importance of ensuring code reliability and avoiding runtime failures, and presenting strategies for both user and core infrastructure teams to enforce constraints and prevent misuse.', 'duration': 598.538, 'highlights': ['The chapter discusses the usage of library code and constraints in software development. The chapter explores the dynamic between core infrastructure and developer teams working with library code, emphasizing the significance of these roles in tech companies and the different perspectives on the type of work and technical challenges involved.', 'The importance of ensuring code reliability and avoiding runtime failures is emphasized. The discussion highlights the importance of writing code that can fail before runtime, with the example of creating tests to detect potential failures in the code before deployment, ensuring robustness and reliability.', 'Strategies for both user and core infrastructure teams to enforce constraints and prevent misuse are presented. The chapter presents strategies for both user and core infrastructure teams to enforce constraints and prevent misuse of library code, showcasing examples of how user code can enforce constraints on library code and how core infrastructure teams can mitigate potential misuse by external users.']}], 'duration': 750.482, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt41165621.jpg', 'highlights': ['The chapter emphasizes the significance of understanding metaclasses, decorators, generators, and context managers as powerful mental models for Python expertise.', 'The chapter stresses the clarity and importance of understanding the metaclasses feature in Python, despite common warnings against it.', 'The tutorial aims to emphasize the significance of understanding metaclasses, decorators, generators, and context managers as powerful mental models for Python expertise.', 'The chapter discusses the usage of library code and constraints in software development, emphasizing the significance of these roles in tech companies and the different perspectives on the type of work and technical challenges involved.', 'The importance of ensuring code reliability and avoiding runtime failures is emphasized.', 'Strategies for both user and core infrastructure teams to enforce constraints and prevent misuse are presented.']}, {'end': 2410.65, 'segs': [{'end': 1960.505, 'src': 'embed', 'start': 1938.054, 'weight': 1, 'content': [{'end': 1946.221, 'text': 'is protocol-orientated, but that the entire Python language itself has a notion of hooks and protocols and safety valves within it.', 'start': 1938.054, 'duration': 8.167}, {'end': 1948.403, 'text': 'I want to show you something kind of interesting.', 'start': 1946.982, 'duration': 1.421}, {'end': 1960.505, 'text': "One thing that a lot of people who come to Python from other languages don't realize is that Python is a much simpler language than you might appreciate.", 'start': 1951.736, 'duration': 8.769}], 'summary': 'Python has hooks, protocols, and safety valves, making it simpler than expected.', 'duration': 22.451, 'max_score': 1938.054, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt41938054.jpg'}, {'end': 2004.344, 'src': 'embed', 'start': 1977.983, 'weight': 0, 'content': [{'end': 1984.668, 'text': "If you look at all the different optimizations that the Visual Studio compiler can perform on code, there's an enormous amount of complexity there.", 'start': 1977.983, 'duration': 6.685}, {'end': 1988.531, 'text': 'Python, it turns out, is a much, much simpler language.', 'start': 1985.569, 'duration': 2.962}, {'end': 1997.559, 'text': 'Python code runs from top to bottom linearly, and almost everything that you see in Python, almost every statement that you see in Python,', 'start': 1989.092, 'duration': 8.467}, {'end': 2004.344, 'text': 'with the exception of Two of them, are actually executable runtime code.', 'start': 1997.559, 'duration': 6.785}], 'summary': 'Visual studio compiler has complex optimizations. python is a simpler language with linear execution.', 'duration': 26.361, 'max_score': 1977.983, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt41977983.jpg'}, {'end': 2264.946, 'src': 'heatmap', 'start': 2057.338, 'weight': 0.867, 'content': [{'end': 2061.88, 'text': 'Create a bar method under this foo object 10 times.', 'start': 2057.338, 'duration': 4.542}, {'end': 2065.424, 'text': 'Only one of them will survive.', 'start': 2064.283, 'duration': 1.141}, {'end': 2068.246, 'text': 'The last one will call all the previous ones.', 'start': 2066.105, 'duration': 2.141}, {'end': 2074.11, 'text': 'But Python accepts this as syntax because this class statement is fundamentally executable code.', 'start': 2068.786, 'duration': 5.324}, {'end': 2080.355, 'text': 'Now I told you, and the direction where we started this was talking about Python as a protocol-orientated language.', 'start': 2074.931, 'duration': 5.424}, {'end': 2082.437, 'text': "Let's see something kind of interesting.", 'start': 2081.176, 'duration': 1.261}, {'end': 2088.223, 'text': "I'm just going to create a function, and I only need this for wrapping purposes.", 'start': 2085.882, 'duration': 2.341}, {'end': 2094.226, 'text': 'Let me create my base class inside some function.', 'start': 2091.885, 'duration': 2.341}, {'end': 2100.169, 'text': 'And let me use a function in a module in the Python standard library called dis.', 'start': 2094.987, 'duration': 5.182}, {'end': 2101.89, 'text': 'Dis stands for disassemble.', 'start': 2100.609, 'duration': 1.281}, {'end': 2107.073, 'text': "Let's disassemble this and see what actually happens in the Python bytecode.", 'start': 2102.59, 'duration': 4.483}, {'end': 2109.674, 'text': 'What we see is something kind of interesting.', 'start': 2107.773, 'duration': 1.901}, {'end': 2114.084, 'text': "we see that there's this thing in the Python bytecode called load build class.", 'start': 2110.762, 'duration': 3.322}, {'end': 2119.628, 'text': "It's an actual executable runtime instruction in the Python interpreter for creating a class.", 'start': 2114.424, 'duration': 5.204}, {'end': 2121.569, 'text': 'Well, hold on a second.', 'start': 2120.649, 'duration': 0.92}, {'end': 2125.132, 'text': 'In the very first example I showed you,', 'start': 2122.81, 'duration': 2.322}, {'end': 2136.079, 'text': 'I said there typically tends to be in Python some correspondence between some top level syntax or function and some underscore method that implements that syntax or function.', 'start': 2125.132, 'duration': 10.947}, {'end': 2139.894, 'text': 'There happens to be some top level mechanism here.', 'start': 2137.093, 'duration': 2.801}, {'end': 2144.036, 'text': "It's not explicitly syntax, it's not explicitly a function for building a class.", 'start': 2140.194, 'duration': 3.842}, {'end': 2146.937, 'text': 'It turns out in Python, there is a hook.', 'start': 2145.137, 'duration': 1.8}, {'end': 2154.021, 'text': 'There is an underscore function that allows you to hook into and to do things with the process of building classes.', 'start': 2147.238, 'duration': 6.783}, {'end': 2159.843, 'text': "And I bet you can guess what it's called, because, just like the correspondence between repper and double underscore,", 'start': 2154.901, 'duration': 4.942}, {'end': 2165.346, 'text': "repper len and double underscore, len adding and double underscore add, it's the same thing here.", 'start': 2159.843, 'duration': 5.503}, {'end': 2169.41, 'text': "There's a function of Python called build class.", 'start': 2167.449, 'duration': 1.961}, {'end': 2178.492, 'text': 'It sits on a module called the built-ins.', 'start': 2170.01, 'duration': 8.482}, {'end': 2189.495, 'text': "So if I define a function here called, we'll do it like this.", 'start': 2178.512, 'duration': 10.983}, {'end': 2206.718, 'text': "If I do this, I'll capture the original build class, I'll write my own build class, I'll import from the built-ins and I'll swap them out.", 'start': 2199.411, 'duration': 7.307}, {'end': 2210.741, 'text': 'Here, I can patch into what Python actually does when it creates classes.', 'start': 2207.318, 'duration': 3.423}, {'end': 2212.583, 'text': "And I won't do anything interesting in here.", 'start': 2211.382, 'duration': 1.201}, {'end': 2215.626, 'text': "I'll just print out all the arguments that are passed.", 'start': 2213.384, 'duration': 2.242}, {'end': 2224.314, 'text': "Okay? And so let's run our Python script one more time.", 'start': 2220.931, 'duration': 3.383}, {'end': 2236.874, 'text': "python-i user.py and you can see here's the class that was created.", 'start': 2225.969, 'duration': 10.905}, {'end': 2244.02, 'text': 'In fact, you can even see I caught another class that was being built that was probably being built somewhere in the interactive interpreter itself.', 'start': 2237.094, 'duration': 6.926}, {'end': 2250.126, 'text': 'But the most important one that you can see is I actually can catch the building of this class.', 'start': 2244.32, 'duration': 5.806}, {'end': 2252.308, 'text': "And you can see there's some interesting things that I passed.", 'start': 2250.546, 'duration': 1.762}, {'end': 2256.932, 'text': 'I passed the name of the class, I passed its basis, and I passed a function.', 'start': 2252.708, 'duration': 4.224}, {'end': 2259.584, 'text': "and I'm past no other arguments.", 'start': 2258.183, 'duration': 1.401}, {'end': 2264.946, 'text': "Well, what I can do, now that I can see the class that I'm building is, I could hook into this and I could do something with it.", 'start': 2260.264, 'duration': 4.682}], 'summary': 'Python allows hooking into class creation using build class function.', 'duration': 207.608, 'max_score': 2057.338, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt42057338.jpg'}, {'end': 2136.079, 'src': 'embed', 'start': 2107.773, 'weight': 2, 'content': [{'end': 2109.674, 'text': 'What we see is something kind of interesting.', 'start': 2107.773, 'duration': 1.901}, {'end': 2114.084, 'text': "we see that there's this thing in the Python bytecode called load build class.", 'start': 2110.762, 'duration': 3.322}, {'end': 2119.628, 'text': "It's an actual executable runtime instruction in the Python interpreter for creating a class.", 'start': 2114.424, 'duration': 5.204}, {'end': 2121.569, 'text': 'Well, hold on a second.', 'start': 2120.649, 'duration': 0.92}, {'end': 2125.132, 'text': 'In the very first example I showed you,', 'start': 2122.81, 'duration': 2.322}, {'end': 2136.079, 'text': 'I said there typically tends to be in Python some correspondence between some top level syntax or function and some underscore method that implements that syntax or function.', 'start': 2125.132, 'duration': 10.947}], 'summary': 'Python bytecode includes load build class for class creation.', 'duration': 28.306, 'max_score': 2107.773, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt42107773.jpg'}, {'end': 2405.424, 'src': 'embed', 'start': 2380.135, 'weight': 3, 'content': [{'end': 2387.939, 'text': "but it's to show you that this idea of Python being a protocol-orientated language is actually quite a common pattern and quite a fundamental piece of Python.", 'start': 2380.135, 'duration': 7.804}, {'end': 2390.301, 'text': 'Almost everything that the Python language does.', 'start': 2388.32, 'duration': 1.981}, {'end': 2396.364, 'text': 'in an execution context, like building classes, creating functions, importing modules, you can find a way to hook into that.', 'start': 2390.301, 'duration': 6.063}, {'end': 2400.687, 'text': 'Once you can find a way to hook into that, you can start doing things that you want to do, like check.', 'start': 2396.745, 'duration': 3.942}, {'end': 2405.424, 'text': 'is my user code going to break from the perspective of the library author?', 'start': 2402.341, 'duration': 3.083}], 'summary': "Python's protocol-orientated approach is fundamental in its design, enabling extensive customization and control over user code.", 'duration': 25.289, 'max_score': 2380.135, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt42380135.jpg'}], 'start': 1919.025, 'title': 'Python as a protocol-oriented language', 'summary': "Delves into python's protocol-oriented nature, highlighting its simplicity in comparison to c++ and java, and its capability to execute almost every statement at runtime. it also explores how python enables the execution of class statements as executable code, demonstrating the load build class bytecode instruction and the ability to hook into and modify class creation using the build class function, illustrating the fundamental nature of python as a protocol-oriented language.", 'chapters': [{'end': 2023.14, 'start': 1919.025, 'title': "Python's protocol-orientated language", 'summary': "Discusses python's protocol-orientated nature, its simplicity compared to c++ and java, and the runtime executability of almost every statement.", 'duration': 104.115, 'highlights': ['Python code runs linearly from top to bottom, and almost every statement is executable runtime code, unlike C++ or Java, making Python a much simpler language.', "Python's entire language has a notion of hooks, protocols, and safety valves, contributing to its categorization as a protocol-orientated language.", 'Python is simpler than C++ and Java, as it lacks the complexity of compile-time steps and extensive optimizations performed by compilers.', "Coming from C++ or Java, individuals may not realize the simplicity of Python's language structure and the executable nature of statements like class declarations."]}, {'end': 2410.65, 'start': 2023.8, 'title': 'Python protocol-orientated language', 'summary': 'Explores how python allows for executing class statements as executable code, demonstrating the load build class bytecode instruction, and the ability to hook into and modify class creation using the build class function, showcasing the fundamental nature of python as a protocol-orientated language.', 'duration': 386.85, 'highlights': ['Python allows for executing class statements as executable code, demonstrating the load build class bytecode instruction. Demonstrates the ability to execute class statements as code and showcases the load build class bytecode instruction in the Python interpreter.', 'Python provides the ability to hook into and modify class creation using the build class function, showcasing the fundamental nature of Python as a protocol-orientated language. Highlights the capability to hook into and modify class creation using the build class function, emphasizing the protocol-orientated nature of Python.', "The concept of Python being a protocol-orientated language is fundamental to almost everything that the Python language does in an execution context. Emphasizes the fundamental nature of Python as a protocol-orientated language and its impact on various aspects of Python's execution context."]}], 'duration': 491.625, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt41919025.jpg', 'highlights': ['Python code runs linearly from top to bottom, and almost every statement is executable runtime code, unlike C++ or Java, making Python a much simpler language.', "Python's entire language has a notion of hooks, protocols, and safety valves, contributing to its categorization as a protocol-orientated language.", 'Python allows for executing class statements as executable code, demonstrating the load build class bytecode instruction.', 'Python provides the ability to hook into and modify class creation using the build class function, showcasing the fundamental nature of Python as a protocol-orientated language.']}, {'end': 3189.617, 'segs': [{'end': 2499.141, 'src': 'embed', 'start': 2454.232, 'weight': 0, 'content': [{'end': 2458.434, 'text': 'but fundamentally allow you to intercept the construction of derived types.', 'start': 2454.232, 'duration': 4.202}, {'end': 2469.76, 'text': 'The method that you care about here is called new, and it takes four arguments, bases, body, and the name bases in the body.', 'start': 2459.715, 'duration': 10.045}, {'end': 2482.433, 'text': "And we'll see, where it gives us an opportunity to actually perform our check.", 'start': 2475.983, 'duration': 6.45}, {'end': 2497.251, 'text': 'You can see it got called right here.', 'start': 2490.223, 'duration': 7.028}, {'end': 2499.141, 'text': 'with our derived class.', 'start': 2498.24, 'duration': 0.901}], 'summary': "The 'new' method allows intercepting construction of derived types with four arguments.", 'duration': 44.909, 'max_score': 2454.232, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt42454232.jpg'}, {'end': 2635.4, 'src': 'embed', 'start': 2610.086, 'weight': 1, 'content': [{'end': 2617.47, 'text': 'In this case metaclasses are how you can make sure that if you only control the code on the left-hand side of the screen,', 'start': 2610.086, 'duration': 7.384}, {'end': 2620.292, 'text': 'you can still enforce constraints on the code on the right-hand side of the screen.', 'start': 2617.47, 'duration': 2.822}, {'end': 2626.015, 'text': 'You can enforce constraints down the class hierarchy from a base class to a derived class.', 'start': 2620.772, 'duration': 5.243}, {'end': 2631.878, 'text': 'This is one approach using a metaclass that just intercepts the construction of the class.', 'start': 2626.735, 'duration': 5.143}, {'end': 2635.4, 'text': 'And the second is even easier.', 'start': 2632.599, 'duration': 2.801}], 'summary': 'Metaclasses enforce constraints on class hierarchy from base to derived class.', 'duration': 25.314, 'max_score': 2610.086, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt42610086.jpg'}, {'end': 2723.247, 'src': 'embed', 'start': 2695.934, 'weight': 2, 'content': [{'end': 2700.956, 'text': 'And so in Python 3.6, a new feature was used, or a new feature was added called init subclass.', 'start': 2695.934, 'duration': 5.022}, {'end': 2708.878, 'text': 'And init subclass, I think it goes here, just gives you a method.', 'start': 2701.656, 'duration': 7.222}, {'end': 2713.96, 'text': 'that allows you to hook into when a subclass of some class is being initialized.', 'start': 2709.997, 'duration': 3.963}, {'end': 2714.921, 'text': "And that's it.", 'start': 2714.52, 'duration': 0.401}, {'end': 2717.843, 'text': 'And I think it goes here.', 'start': 2715.681, 'duration': 2.162}, {'end': 2718.343, 'text': "Let's find out.", 'start': 2717.883, 'duration': 0.46}, {'end': 2723.247, 'text': 'If Brett were here, he could tell you exactly where it goes.', 'start': 2721.646, 'duration': 1.601}], 'summary': 'Python 3.6 introduced init subclass feature for hooking into subclass initialization.', 'duration': 27.313, 'max_score': 2695.934, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt42695934.jpg'}, {'end': 3018.132, 'src': 'heatmap', 'start': 2808.686, 'weight': 0.919, 'content': [{'end': 2811.308, 'text': 'This is my simple story about metaclasses.', 'start': 2808.686, 'duration': 2.622}, {'end': 2816.331, 'text': "Metaclasses are a feature that we're often told that are an expert level feature.", 'start': 2812.629, 'duration': 3.702}, {'end': 2817.632, 'text': "You're not supposed to ever use them.", 'start': 2816.351, 'duration': 1.281}, {'end': 2818.792, 'text': 'You should shy away from them.', 'start': 2817.652, 'duration': 1.14}, {'end': 2823.275, 'text': 'You should cover your eyes before you read code that includes metaclasses.', 'start': 2819.273, 'duration': 4.002}, {'end': 2826.011, 'text': "And it simply isn't that.", 'start': 2825.131, 'duration': 0.88}, {'end': 2832.455, 'text': "It simply is that for all of these advanced features, there's usually one or two very clear metaphors to understand what that feature's all about.", 'start': 2826.492, 'duration': 5.963}, {'end': 2837.338, 'text': "And once you understand what that feature's all about, there's a lot of details you need to read through in documentation.", 'start': 2833.015, 'duration': 4.323}, {'end': 2841.38, 'text': "That's the approach I wanna take for the remaining three features I wanna show you.", 'start': 2838.138, 'duration': 3.242}, {'end': 2845.502, 'text': 'The next feature is a very simple feature called decorators.', 'start': 2842.36, 'duration': 3.142}, {'end': 2847.123, 'text': "I'm sure some of you have already seen this feature.", 'start': 2845.682, 'duration': 1.441}, {'end': 2855.125, 'text': 'But I want to show you kind of where this feature comes from.', 'start': 2852.602, 'duration': 2.523}, {'end': 2857.828, 'text': "It's a very simple and very boring feature indeed.", 'start': 2855.145, 'duration': 2.683}, {'end': 2859.71, 'text': "And you've probably seen this feature before.", 'start': 2858.209, 'duration': 1.501}, {'end': 2869.122, 'text': "It's this little at that shows up on top of some function definition.", 'start': 2860.311, 'duration': 8.811}, {'end': 2873.791, 'text': 'This little at with a dotted name, so you see something like a.b.c.', 'start': 2870.37, 'duration': 3.421}, {'end': 2877.853, 'text': 'For those of you who are very familiar with this feature,', 'start': 2875.832, 'duration': 2.021}, {'end': 2882.355, 'text': "you might wonder why you can't do this or why there are limitations to what you can put in the decorator line.", 'start': 2877.853, 'duration': 4.502}, {'end': 2884.916, 'text': 'The answer for it is a really stupid answer.', 'start': 2883.395, 'duration': 1.521}, {'end': 2887.357, 'text': 'There is no good reason, but there is a limitation.', 'start': 2885.316, 'duration': 2.041}, {'end': 2892.999, 'text': "For those of you who haven't seen this feature before, I want to show you something about Python,", 'start': 2889.558, 'duration': 3.441}, {'end': 2895.26, 'text': 'something very core and very fundamental about Python.', 'start': 2892.999, 'duration': 2.261}, {'end': 2901.756, 'text': 'I told you when we talked about metaclasses, that Python is a live language.', 'start': 2896.221, 'duration': 5.535}, {'end': 2911.36, 'text': 'There is no separate step that turns function definitions into bags of bits tagged in some ELF binary or some PE binary somewhere.', 'start': 2902.216, 'duration': 9.144}, {'end': 2915.042, 'text': 'That a function definition is actually a live thing.', 'start': 2911.9, 'duration': 3.142}, {'end': 2916.502, 'text': 'It actually runs at runtime.', 'start': 2915.242, 'duration': 1.26}, {'end': 2920.864, 'text': "There's actually executable code associated with this def f.", 'start': 2916.542, 'duration': 4.322}, {'end': 2924.826, 'text': 'Okay? So let me show you that in practice.', 'start': 2920.864, 'duration': 3.962}, {'end': 2931.688, 'text': "Here's a function called add that adds two values.", 'start': 2929.326, 'duration': 2.362}, {'end': 2938.932, 'text': 'Let me create a little separation down here and let me run that.', 'start': 2936.251, 'duration': 2.681}, {'end': 2948.719, 'text': 'Here I have my function add and I can add two values.', 'start': 2946.017, 'duration': 2.702}, {'end': 2955.478, 'text': 'The first thing I did in my terminal is I looked at the function itself and I got a return value.', 'start': 2950.953, 'duration': 4.525}, {'end': 2960.424, 'text': 'You can see that the Python interpreter can actually tell me where physically in memory this function exists.', 'start': 2955.819, 'duration': 4.605}, {'end': 2966.211, 'text': "And in fact this add function is an object, and I can ask it all sorts of things, like what's your name??", 'start': 2961.285, 'duration': 4.926}, {'end': 2969.775, 'text': "What's your module where you were defined??", 'start': 2967.412, 'duration': 2.363}, {'end': 2971.057, 'text': 'I can ask it.', 'start': 2970.476, 'duration': 0.581}, {'end': 2976.486, 'text': "Let's give that a default value there and run this again.", 'start': 2974.445, 'duration': 2.041}, {'end': 2981.029, 'text': 'I can say add, what are your defaults? It can tell me what default values it had.', 'start': 2976.506, 'duration': 4.523}, {'end': 2989.353, 'text': "I can say, what's your code? What code do you contain? This is actually the byte codes for this add function.", 'start': 2981.709, 'duration': 7.644}, {'end': 2990.554, 'text': 'You can see them right here.', 'start': 2989.773, 'duration': 0.781}, {'end': 2999.939, 'text': "I could ask it things like, how many local variables do you have? That's your name.", 'start': 2992.135, 'duration': 7.804}, {'end': 3004.541, 'text': "There's one more that's interesting, var names.", 'start': 3002.639, 'duration': 1.902}, {'end': 3007.783, 'text': 'I can ask you what variable names do you interact with?', 'start': 3004.581, 'duration': 3.202}, {'end': 3009.465, 'text': 'What are the variable names of your signature x and y??', 'start': 3007.823, 'duration': 1.642}, {'end': 3013.708, 'text': 'You can do all sorts of things to interact live with this function.', 'start': 3009.625, 'duration': 4.083}, {'end': 3018.132, 'text': "Well, it's interesting that this function itself is a runtime object.", 'start': 3014.369, 'duration': 3.763}], 'summary': 'Metaclasses and decorators are core python features, with metaclasses being a misunderstood concept and decorators being a simple yet powerful feature. python functions are live objects and can be interacted with at runtime.', 'duration': 209.446, 'max_score': 2808.686, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt42808686.jpg'}, {'end': 3070.702, 'src': 'embed', 'start': 3045.626, 'weight': 3, 'content': [{'end': 3052.732, 'text': "Every Python structure that you interact with, whether it's an object or a function or a generator, has some runtime life, has some runtime existence.", 'start': 3045.626, 'duration': 7.106}, {'end': 3055.694, 'text': 'You can see it in memory.', 'start': 3053.532, 'duration': 2.162}, {'end': 3059.537, 'text': 'You can ask it questions like what module were you defined in?', 'start': 3056.314, 'duration': 3.223}, {'end': 3067.179, 'text': "You can even ask it very useful questions like if you use the inspect module, You can say what's your source code?", 'start': 3059.977, 'duration': 7.202}, {'end': 3070.702, 'text': "And it'll tell you its source code right back out.", 'start': 3068.16, 'duration': 2.542}], 'summary': 'Python structures have runtime existence, can be inspected, and reveal source code.', 'duration': 25.076, 'max_score': 3045.626, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt43045626.jpg'}], 'start': 2410.65, 'title': 'Python metaclasses and constraints enforcement', 'summary': "Covers the use of meta classes to enforce constraints, including the 'new' method for checks, and explores the concept of metaclasses, init subclass feature, and the live nature of python functions and decorators.", 'chapters': [{'end': 2548.163, 'start': 2410.65, 'title': 'Python meta classes and enforcing constraints', 'summary': "Discusses the importance of recognizing a pattern, options for solving it, and the use of meta classes in python to enforce constraints from derived class to base classes, with a focus on the 'new' method and its usage for performing checks.", 'duration': 137.513, 'highlights': ['The chapter emphasizes the importance of recognizing the existing pattern, understanding available solutions, and avoiding inappropriate methods, with the build class being mentioned as an option for use but not as the preferred solution.', "The discussion introduces the use of meta classes in Python to enforce constraints from derived class to base classes, specifically highlighting the 'new' method, which takes four arguments and provides an opportunity to perform checks during the construction of derived types.", "The speaker demonstrates how to use the 'new' method of meta classes to intercept the construction of derived types and perform checks, using the example of intercepting the bar method and enforcing a specific behavior by utilizing assert and raise statements.", 'The chapter mentions the need to find an alternative approach for enforcing constraints from the base class to derived class, emphasizing the limitations of adding assert lines and the requirement to fundamentally intercept how classes are constructed.']}, {'end': 3189.617, 'start': 2548.163, 'title': 'Python metaclasses and decorators', 'summary': 'Discusses the concept of metaclasses in python, highlighting their usefulness in enforcing constraints on class hierarchies, and introduces the init subclass feature as a simpler alternative. it then delves into the live nature of python functions and the limitations and uses of decorators, showcasing the runtime existence of python structures and the ability to interact with them.', 'duration': 641.454, 'highlights': ['Metaclasses enforce constraints on class hierarchies, providing a clear and unambiguous metaphor for their usefulness. Metaclasses help enforce constraints down the class hierarchy from a base class to a derived class, showcasing their usefulness in controlling the code on the left-hand side of the screen and intercepting the construction of the class.', 'The init subclass feature in Python 3.6 is introduced as a simpler alternative to metaclasses, providing a method to hook into when a subclass of some class is being initialized. The init subclass feature allows for intercepting the initialization of a subclass, offering a more straightforward approach compared to metaclasses and addressing the complexity associated with metaclasses.', 'Python functions are live objects with runtime existence, allowing interactions such as querying their source code, module, and line number. Python functions are revealed to be live objects with runtime existence, enabling interactions such as querying their source code, module, line number, default values, and variable names, providing insights into their dynamic nature and capabilities.', "The limitations and uses of decorators are explored, emphasizing the live nature of Python functions and the ability to interact with them at runtime. The chapter delves into the limitations and uses of decorators, shedding light on the live nature of Python functions and the ability to interact with them at runtime, highlighting the fundamental and dynamic aspects of Python's functionality."]}], 'duration': 778.967, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt42410650.jpg', 'highlights': ["The 'new' method of meta classes intercepts construction of derived types and performs checks.", 'Metaclasses enforce constraints from base to derived classes, providing a clear metaphor for their usefulness.', 'The init subclass feature in Python 3.6 offers a simpler alternative to metaclasses for intercepting subclass initialization.', 'Python functions are live objects with runtime existence, enabling interactions such as querying source code and module.']}, {'end': 3687.197, 'segs': [{'end': 3303.381, 'src': 'embed', 'start': 3277.42, 'weight': 1, 'content': [{'end': 3287.723, 'text': 'And when the task at hand becomes harder or more complex or the requirements change, you can change your code in a very simple fashion.', 'start': 3277.42, 'duration': 10.303}, {'end': 3295.239, 'text': 'to linearly extend its functionality without having to rewrite everything from scratch.', 'start': 3289.298, 'duration': 5.941}, {'end': 3303.381, 'text': 'This is a fundamental difference between writing code in Python and writing code in a language like C++.', 'start': 3296.659, 'duration': 6.722}], 'summary': 'In python, code can be easily modified to extend functionality without rewriting everything from scratch, unlike in c++.', 'duration': 25.961, 'max_score': 3277.42, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt43277420.jpg'}, {'end': 3637.299, 'src': 'heatmap', 'start': 3556.381, 'weight': 0.925, 'content': [{'end': 3566.487, 'text': 'And you can see this here is a wrapper that calls the function that was passed in and wraps it with some timing behavior before and after and printing something out.', 'start': 3556.381, 'duration': 10.106}, {'end': 3570.589, 'text': "Couldn't I do that? I can define functions at runtime.", 'start': 3568.048, 'duration': 2.541}, {'end': 3571.57, 'text': 'I can define functions anywhere.', 'start': 3570.609, 'duration': 0.961}, {'end': 3587.337, 'text': 'Then, instead of all this nastiness, changing all this user code, I could just say add equals timer of add and sub equals timer of sub.', 'start': 3572.782, 'duration': 14.555}, {'end': 3592.562, 'text': 'You could see it added that behavior across everything.', 'start': 3590.16, 'duration': 2.402}, {'end': 3597.866, 'text': "And you can see when I do that, what I'm doing is I'm taking one function, I'm wrapping it with some behavior.", 'start': 3593.703, 'duration': 4.163}, {'end': 3605.872, 'text': "I'm taking one aspect or one piece of core or common functionality, and I'm wrapping a bunch of different functions in a really simple fashion.", 'start': 3598.427, 'duration': 7.445}, {'end': 3615.019, 'text': "And all I'm doing is I'm creating a new function that takes the original function and wraps it with a little bit of behavior before and after.", 'start': 3607.013, 'duration': 8.006}, {'end': 3615.84, 'text': "And that's it.", 'start': 3615.459, 'duration': 0.381}, {'end': 3620.017, 'text': 'And it turns out that Python wants to make this a little bit easier for you,', 'start': 3617.076, 'duration': 2.941}, {'end': 3625.919, 'text': 'because this pattern of something equals call a function on that original thing that exists.', 'start': 3620.017, 'duration': 5.902}, {'end': 3627.96, 'text': "And that's what a decorator is in Python.", 'start': 3626.459, 'duration': 1.501}, {'end': 3635.557, 'text': "A decorator is merely syntax That's equivalent to the line that says this.", 'start': 3629.28, 'duration': 6.277}, {'end': 3637.299, 'text': 'Sub equals timer of sub.', 'start': 3636.018, 'duration': 1.281}], 'summary': 'Python decorators add timing behavior to functions, simplifying code and adding functionality across multiple functions.', 'duration': 80.918, 'max_score': 3556.381, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt43556381.jpg'}, {'end': 3625.919, 'src': 'embed', 'start': 3598.427, 'weight': 2, 'content': [{'end': 3605.872, 'text': "I'm taking one aspect or one piece of core or common functionality, and I'm wrapping a bunch of different functions in a really simple fashion.", 'start': 3598.427, 'duration': 7.445}, {'end': 3615.019, 'text': "And all I'm doing is I'm creating a new function that takes the original function and wraps it with a little bit of behavior before and after.", 'start': 3607.013, 'duration': 8.006}, {'end': 3615.84, 'text': "And that's it.", 'start': 3615.459, 'duration': 0.381}, {'end': 3620.017, 'text': 'And it turns out that Python wants to make this a little bit easier for you,', 'start': 3617.076, 'duration': 2.941}, {'end': 3625.919, 'text': 'because this pattern of something equals call a function on that original thing that exists.', 'start': 3620.017, 'duration': 5.902}], 'summary': 'Python simplifies wrapping functions for easier behavior modification.', 'duration': 27.492, 'max_score': 3598.427, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt43598427.jpg'}, {'end': 3684.634, 'src': 'embed', 'start': 3645.565, 'weight': 0, 'content': [{'end': 3647.466, 'text': 'So this is what our final example would look like.', 'start': 3645.565, 'duration': 1.901}, {'end': 3652.25, 'text': 'We would have started with code that looked like this.', 'start': 3647.987, 'duration': 4.263}, {'end': 3658.635, 'text': 'We would have had to add only the timer code and then two decorators.', 'start': 3653.431, 'duration': 5.204}, {'end': 3666.949, 'text': "and we'd be able to very easily slip in this extra functionality we want without having to rewrite all this user code ourselves.", 'start': 3659.827, 'duration': 7.122}, {'end': 3669.83, 'text': "That's the core of what a decorator in Python is.", 'start': 3667.789, 'duration': 2.041}, {'end': 3684.634, 'text': 'At its core it is very simple syntax to just allow you to write an ugly pattern sub equals timer of sub in a slightly nicer way in a slightly nicer place at the top.', 'start': 3671.63, 'duration': 13.004}], 'summary': 'Python decorators add functionality to code easily.', 'duration': 39.069, 'max_score': 3645.565, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt43645565.jpg'}], 'start': 3191.823, 'title': 'Python programming features', 'summary': "Explores python's preference for simple, quick code and linear extension, contrasting it with c++. it also discusses decorators in python, showcasing a more efficient way to add extra functionality without rewriting user code.", 'chapters': [{'end': 3430.784, 'start': 3191.823, 'title': 'Python code complexity', 'summary': "Explores the python programming language's preference for writing the simplest, quickest code, and its ability to linearly extend functionality without rewriting everything, in contrast to c++.", 'duration': 238.961, 'highlights': ['Python developers prioritize writing the simplest, quickest code over an absolutely perfect solution, allowing for linear extension of functionality without rewriting everything. ', "In Python, there's a focus on writing the simplest code for the current problem and then extending it as the problem becomes more complex, in contrast to the upfront design required in C++. ", 'Adding tracking code in multiple places in the codebase creates complexity and the need for rewriting code, highlighting the importance of finding a better way to handle such situations. Mention of adding tracking code in three places instead of one, and then in two places instead of one.']}, {'end': 3687.197, 'start': 3431.587, 'title': 'Python decorators and function wrapping', 'summary': 'Discusses the concept of decorators in python, demonstrating how to wrap functions with additional behavior using the timer function, ultimately showcasing a more efficient way to add extra functionality without rewriting user code.', 'duration': 255.61, 'highlights': ['Python decorators are a way to wrap a function with some behavior before and after its execution, providing a more efficient way to add extra functionality without rewriting user code. This explanation provides an overview of the main topic of the transcript, emphasizing the purpose and benefit of using decorators in Python.', 'The timer function is used to wrap other functions with timing behavior, demonstrating the process of creating a new function that takes the original function and wraps it with some timing behavior before and after execution. This highlights the specific use of the timer function to add timing behavior to other functions, showcasing the practical application of decorators in Python.', 'Python decorators allow for the dynamic construction of a function to wrap behavior, simplifying the process of adding functionality to existing functions without altering the user code. This point emphasizes the convenience and flexibility offered by Python decorators in dynamically enhancing the behavior of functions without requiring extensive modifications to the existing code.']}], 'duration': 495.374, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt43191823.jpg', 'highlights': ['Python decorators simplify adding functionality to existing functions without altering user code.', 'Python prioritizes writing simple, quick code for current problems and extending it as problems become more complex.', 'Python decorators wrap functions with behavior before and after execution, providing an efficient way to add extra functionality.']}, {'end': 5073.796, 'segs': [{'end': 3740.291, 'src': 'embed', 'start': 3687.197, 'weight': 0, 'content': [{'end': 3700.812, 'text': "it's about allowing you to take this wrapping behavior for functions and to wrap wide swaths of functions in one fashion without having to rewrite a lot of user code or having to even perform a lot of churn on your library code.", 'start': 3687.197, 'duration': 13.615}, {'end': 3702.474, 'text': "That's what a decorator is.", 'start': 3701.593, 'duration': 0.881}, {'end': 3704.897, 'text': 'Go ahead.', 'start': 3704.697, 'duration': 0.2}, {'end': 3713.542, 'text': "So one of the problems here, I think you're identifying.", 'start': 3711.721, 'duration': 1.821}, {'end': 3718.406, 'text': 'Here, I hard-coded the parameters, right? And I even hard-coded the default.', 'start': 3714.403, 'duration': 4.003}, {'end': 3722.189, 'text': 'The real answer is this is where we use star args and star star quarks.', 'start': 3719.127, 'duration': 3.062}, {'end': 3733.298, 'text': 'Now, this decorator works on any function that takes any arbitrary set of positional and keyword parameters and just forwards them on.', 'start': 3724.011, 'duration': 9.287}, {'end': 3740.291, 'text': 'And so now this will work to wrap any function with any set of defaults in any fashion.', 'start': 3735.848, 'duration': 4.443}], 'summary': 'Decorators allow wrapping functions without rewriting code, handling any parameters and defaults.', 'duration': 53.094, 'max_score': 3687.197, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt43687197.jpg'}, {'end': 3975.985, 'src': 'heatmap', 'start': 3879.585, 'weight': 3, 'content': [{'end': 3883.986, 'text': "Now you want to generalize this because you don't want to run it just two times, you want to run it some number of times.", 'start': 3879.585, 'duration': 4.401}, {'end': 3896.328, 'text': "Why can't we just wrap this in another function that takes the n and just return this? Like that, right?", 'start': 3884.026, 'duration': 12.302}, {'end': 3902.935, 'text': 'So now this is a function that takes How many times?', 'start': 3897.268, 'duration': 5.667}, {'end': 3905.516, 'text': 'These are what they call higher order decorators.', 'start': 3903.635, 'duration': 1.881}, {'end': 3908.017, 'text': 'Really not that interesting or that important.', 'start': 3906.116, 'duration': 1.901}, {'end': 3914.599, 'text': "It's a fairly simplistic extension of the idea, which is if you can return one, if you can have a function that returns a function,", 'start': 3908.037, 'duration': 6.562}, {'end': 3918.68, 'text': 'then you can have a function that returns a function, where that inner function then returns another function.', 'start': 3914.599, 'duration': 4.081}, {'end': 3922.561, 'text': 'Ad infinitum, going as deep as you want to solve whatever problem you want.', 'start': 3919.22, 'duration': 3.341}, {'end': 3930.407, 'text': 'There is a very important core concept that is hidden in here, which is what you might call the closure object duality.', 'start': 3923.061, 'duration': 7.346}, {'end': 3936.553, 'text': "It's not something that we have time to look at in this session, but it is a very important duality in Python,", 'start': 3930.968, 'duration': 5.585}, {'end': 3937.954, 'text': "but it's not one of the topics that we can look at.", 'start': 3936.553, 'duration': 1.401}, {'end': 3943.118, 'text': 'But just to show you this in practice, you can see this got called twice, this got called five times.', 'start': 3938.554, 'duration': 4.564}, {'end': 3946.922, 'text': 'So you can write your own n times decorator very easily as well.', 'start': 3943.959, 'duration': 2.963}, {'end': 3953.974, 'text': "And the core of it is just the idea that you start with the wrapper, So this is just your wrapper function, what you're replacing it with.", 'start': 3948.123, 'duration': 5.851}, {'end': 3957.196, 'text': 'The decorator syntax allows you to do that replacing very easily.', 'start': 3954.194, 'duration': 3.002}, {'end': 3963.999, 'text': 'And then in order to get this programmatic behavior, you just add one level, a function outside that constructs the decorator.', 'start': 3958.356, 'duration': 5.643}, {'end': 3965.88, 'text': 'The decorator then constructs the wrapper.', 'start': 3964.379, 'duration': 1.501}, {'end': 3967.701, 'text': 'The wrapper then wraps the function itself.', 'start': 3966.18, 'duration': 1.521}, {'end': 3975.985, 'text': "It is rare that you'll see a decorator deeper than this, just because it's very rare that you have context.", 'start': 3968.842, 'duration': 7.143}], 'summary': 'Higher order decorators can be used to create functions that return functions, allowing for programmatic behavior and solving various problems.', 'duration': 28.432, 'max_score': 3879.585, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt43879585.jpg'}, {'end': 3946.922, 'src': 'embed', 'start': 3923.061, 'weight': 1, 'content': [{'end': 3930.407, 'text': 'There is a very important core concept that is hidden in here, which is what you might call the closure object duality.', 'start': 3923.061, 'duration': 7.346}, {'end': 3936.553, 'text': "It's not something that we have time to look at in this session, but it is a very important duality in Python,", 'start': 3930.968, 'duration': 5.585}, {'end': 3937.954, 'text': "but it's not one of the topics that we can look at.", 'start': 3936.553, 'duration': 1.401}, {'end': 3943.118, 'text': 'But just to show you this in practice, you can see this got called twice, this got called five times.', 'start': 3938.554, 'duration': 4.564}, {'end': 3946.922, 'text': 'So you can write your own n times decorator very easily as well.', 'start': 3943.959, 'duration': 2.963}], 'summary': 'Python has a key duality of closure object and it can be demonstrated with examples of being called twice and five times.', 'duration': 23.861, 'max_score': 3923.061, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt43923061.jpg'}, {'end': 4013.284, 'src': 'embed', 'start': 3987.34, 'weight': 4, 'content': [{'end': 3991.642, 'text': "Decorators are probably the least interesting of all the functions we're going to look at, or one of the features we're going to look at.", 'start': 3987.34, 'duration': 4.302}, {'end': 3995.104, 'text': 'The next feature I want to look at is called generators.', 'start': 3992.462, 'duration': 2.642}, {'end': 3998.585, 'text': 'Now some of you may already know what a generator is.', 'start': 3997.044, 'duration': 1.541}, {'end': 4004.797, 'text': 'Generators are a very interesting and very powerful feature of Python.', 'start': 4002.315, 'duration': 2.482}, {'end': 4013.284, 'text': "They're also a feature that include, where I feel the mental model is often very, what people understand of the mental model is often fairly limited.", 'start': 4004.997, 'duration': 8.287}], 'summary': 'Generators are a powerful feature of python, often with limited understanding.', 'duration': 25.944, 'max_score': 3987.34, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt43987340.jpg'}, {'end': 4173.368, 'src': 'embed', 'start': 4146.308, 'weight': 5, 'content': [{'end': 4149.629, 'text': "It's actually a couple of different approaches you could think of for how you do this.", 'start': 4146.308, 'duration': 3.321}, {'end': 4156.71, 'text': 'The core idea here is that fundamentally there is some very nice syntax.', 'start': 4151.309, 'duration': 5.401}, {'end': 4159.919, 'text': 'and then some object model that everything kind of sits in.', 'start': 4157.917, 'duration': 2.002}, {'end': 4162.661, 'text': 'And this is closer to what the object model itself looks like.', 'start': 4160.319, 'duration': 2.342}, {'end': 4171.367, 'text': "You can think that add1 is some object that kind of looks something like this, although we'll remove the statefulness stuff,", 'start': 4163.582, 'duration': 7.785}, {'end': 4173.368, 'text': 'just so that the two examples are at parity.', 'start': 4171.367, 'duration': 2.001}], 'summary': 'Various approaches to creating an object model with nice syntax.', 'duration': 27.06, 'max_score': 4146.308, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt44146308.jpg'}, {'end': 4330.715, 'src': 'embed', 'start': 4299.201, 'weight': 7, 'content': [{'end': 4300.382, 'text': 'What if I only care about the first value?', 'start': 4299.201, 'duration': 1.181}, {'end': 4301.142, 'text': 'How much memory does it use?', 'start': 4300.402, 'duration': 0.74}, {'end': 4305.617, 'text': 'Same, right?', 'start': 4305.157, 'duration': 0.46}, {'end': 4307.078, 'text': 'What if I care about all the elements?', 'start': 4305.998, 'duration': 1.08}, {'end': 4308.059, 'text': 'How much memory does it use?', 'start': 4307.138, 'duration': 0.921}, {'end': 4308.82, 'text': 'Same.', 'start': 4308.619, 'duration': 0.201}, {'end': 4311.501, 'text': 'This is what we often mean by eager.', 'start': 4310.02, 'duration': 1.481}, {'end': 4317.486, 'text': 'The idea that this function, irrespective of what you actually care about in this computation,', 'start': 4311.902, 'duration': 5.584}, {'end': 4320.628, 'text': 'always takes the exact same amount of memory and the exact same amount of time.', 'start': 4317.486, 'duration': 3.142}, {'end': 4326.252, 'text': "It eagerly gives you the entire result and you're sitting there waiting for the entire result.", 'start': 4321.188, 'duration': 5.064}, {'end': 4330.715, 'text': 'So you can see it gives me the entire result all at once.', 'start': 4326.772, 'duration': 3.943}], 'summary': 'Eager computation uses same memory and time for entire result.', 'duration': 31.514, 'max_score': 4299.201, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt44299201.jpg'}, {'end': 4502.865, 'src': 'embed', 'start': 4472.145, 'weight': 8, 'content': [{'end': 4475.469, 'text': 'you could probably guess what the underscore functions we have to implement would be.', 'start': 4472.145, 'duration': 3.324}, {'end': 4479.253, 'text': "They'd correspond to these two top-level functions here and here.", 'start': 4476.47, 'duration': 2.783}, {'end': 4483.998, 'text': "They'd be iter and they'd be next.", 'start': 4481.115, 'duration': 2.883}, {'end': 4492.607, 'text': 'So what that means is, we can take a class in Python, we can add an iter and a next method, and suddenly that class can be iterated over.', 'start': 4486.02, 'duration': 6.587}, {'end': 4502.865, 'text': 'Well, in the process of that iteration, what could we do? Well, anything arbitrarily, including perform a long computation.', 'start': 4493.874, 'duration': 8.991}], 'summary': 'Implementing iter and next functions in python allows a class to be iterated over, enabling arbitrary actions during iteration.', 'duration': 30.72, 'max_score': 4472.145, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt44472145.jpg'}, {'end': 4694.335, 'src': 'embed', 'start': 4658.24, 'weight': 10, 'content': [{'end': 4664.066, 'text': "This looks really ugly and this is really hard to read, and there's a much simpler way to write it,", 'start': 4658.24, 'duration': 5.826}, {'end': 4667.569, 'text': 'a much simpler formal expression for how to write functions.', 'start': 4664.066, 'duration': 3.503}, {'end': 4672.033, 'text': "There's a much simpler way to write a function that operates in this fashion.", 'start': 4668.11, 'duration': 3.923}, {'end': 4673.815, 'text': "And that's what the generator syntax is.", 'start': 4672.414, 'duration': 1.401}, {'end': 4678.56, 'text': 'The generator syntax is merely something that looks like this.', 'start': 4674.376, 'duration': 4.184}, {'end': 4694.335, 'text': 'And all this means is this thing here, compute, is something that can be iterated over.', 'start': 4688.851, 'duration': 5.484}], 'summary': 'Simpler function syntax introduced, making code more readable and efficient.', 'duration': 36.095, 'max_score': 4658.24, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt44658240.jpg'}, {'end': 4809.728, 'src': 'embed', 'start': 4775.426, 'weight': 12, 'content': [{'end': 4777.527, 'text': 'We have all seen APIs that look like this.', 'start': 4775.426, 'duration': 2.101}, {'end': 4794.805, 'text': "We've all seen APIs that look like this, which have methods that indicate the order in which you have to run functions.", 'start': 4786.957, 'duration': 7.848}, {'end': 4798.629, 'text': "If you don't run this first first, everything blows up.", 'start': 4795.566, 'duration': 3.063}, {'end': 4801.211, 'text': "If you don't run this last last, everything blows up.", 'start': 4798.789, 'duration': 2.422}, {'end': 4809.728, 'text': 'And in the documentation they tell you please run this method, then this method, then this method, because if you do it in any other order,', 'start': 4802.282, 'duration': 7.446}], 'summary': 'Common api design issues include strict method order and risk of errors.', 'duration': 34.302, 'max_score': 4775.426, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt44775426.jpg'}, {'end': 4962.128, 'src': 'embed', 'start': 4933.776, 'weight': 11, 'content': [{'end': 4940.442, 'text': 'the generator runs, its code yields back to the user code, the user code does whatever it wants, goes back to the generator, asks for another value,', 'start': 4933.776, 'duration': 6.666}, {'end': 4940.882, 'text': 'and so on.', 'start': 4940.442, 'duration': 0.44}, {'end': 4945.687, 'text': 'So you have this interleaving of the two pieces of your code, the user code and the library code.', 'start': 4941.183, 'duration': 4.504}, {'end': 4955.255, 'text': "Here in this API, what we'd actually have is similarly when we use this API, we'd ideally want to have some interleaving.", 'start': 4947.188, 'duration': 8.067}, {'end': 4962.128, 'text': 'Because if we could run all three of these methods all at the same time, the API would never have provided us three methods.', 'start': 4956.564, 'duration': 5.564}], 'summary': 'The generator and user code interleave, api should ideally allow simultaneous method execution', 'duration': 28.352, 'max_score': 4933.776, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt44933776.jpg'}, {'end': 5073.796, 'src': 'embed', 'start': 5049.909, 'weight': 13, 'content': [{'end': 5058.391, 'text': 'But here, if the API were provided in this fashion, you could guarantee that the last method was never called before the first or the second method.', 'start': 5049.909, 'duration': 8.482}, {'end': 5062.573, 'text': 'The generator forces that sequencing on you.', 'start': 5059.792, 'duration': 2.781}, {'end': 5064.953, 'text': 'And it forces that sequencing on you,', 'start': 5063.313, 'duration': 1.64}, {'end': 5073.796, 'text': 'because the generator is ultimately a coroutine that allows you this interleaving between two types of code user code and library code.', 'start': 5064.953, 'duration': 8.843}], 'summary': "Api ensures method sequencing, thanks to generator's coroutine functionality.", 'duration': 23.887, 'max_score': 5049.909, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt45049909.jpg'}], 'start': 3687.197, 'title': 'Python features and implementations', 'summary': 'Covers decorators, syntax and object model differences, python generators, and api design, highlighting the practical implementation of decorators, the importance of efficient processing, benefits of using generators, and advantages in api design.', 'chapters': [{'end': 4004.797, 'start': 3687.197, 'title': 'Decorators and higher order decorators', 'summary': 'Explains the concept of decorators, how to create a decorator to run a function n times, and the importance of closure object duality in python, highlighting the versatility and power of decorators and their practical implementation.', 'duration': 317.6, 'highlights': ['The decorator allows wrapping wide swaths of functions in one fashion without having to rewrite a lot of user code or library code.', 'The decorator works on any function that takes any arbitrary set of positional and keyword parameters and forwards them on, making it versatile and adaptable.', 'Creating a decorator to run a function n times involves constructing the decorator by adding one more level to the wrapper function, demonstrating the concept of higher order decorators.', "The closure object duality, while not fully explored, is highlighted as a very important concept in Python, hinting at its significance in understanding Python's functionality.", "Decorators are considered one of the least interesting features compared to other functions, with the next feature to be explored being generators, emphasizing the depth and breadth of Python's capabilities."]}, {'end': 4440.98, 'start': 4004.997, 'title': 'Syntax and object model in code', 'summary': 'Delves into the differences between top-level syntax and object methods, showcasing the fundamental difference between function and class, and the implications of eager computation on time and memory, emphasizing the importance of efficient processing.', 'duration': 435.983, 'highlights': ['The fundamental difference between top-level syntax and object methods The speaker discusses the distinction between top-level syntax and object methods, highlighting the difference between the function and class and their implementation.', 'Implications of eager computation on time and memory The chapter explores the implications of eager computation on time and memory, emphasizing the wastefulness of eagerly giving the entire result set, leading to prolonged waiting times and excessive memory usage.', 'Efficient processing and object model The importance of efficient processing is emphasized, as the speaker rewrites a function as a class, showcasing the significance of iterating through elements one by one and processing them efficiently.']}, {'end': 4774.305, 'start': 4442.14, 'title': 'Python generators', 'summary': 'Explains the concept of python generators, including the corresponding underscore methods, implementation of iter and next methods, and the benefits of using generator formulation over the original function formulation.', 'duration': 332.165, 'highlights': ['Python top-level syntax or functions have corresponding underscore methods that can be implemented, such as iter and next, allowing a class to be iterated over.', 'The iter and next methods can be added to a class in Python to enable iteration, with the iter method returning self and the next method computing and returning values one at a time.', 'The generator syntax provides a simpler way to write functions that can be iterated over, maintaining internal state and yielding values as they are requested by the user.']}, {'end': 5073.796, 'start': 4775.426, 'title': 'Api design and generators', 'summary': 'Discusses the limitations of traditional apis, the benefits of using generators to interleave user and library code, and the concept of coroutines for enforcing sequencing and interleaving, showcasing the advantages of generators in api design.', 'duration': 298.37, 'highlights': ['Generators allow interleaving of user and library code while enforcing sequencing, providing a critical mental model for API design. Generators enable interleaving user and library code while ensuring a fixed sequencing, which is crucial for API design.', 'Traditional APIs lack control over code sequencing, leading to potential errors if methods are not executed in the correct order. Conventional APIs have limitations in controlling code sequencing, increasing the risk of errors if methods are not executed in the specified order.', 'Generators act as coroutines, ensuring the execution order of methods and preventing the out-of-sequence call of functions. Generators serve as coroutines, controlling the order of method execution and preventing out-of-sequence function calls.']}], 'duration': 1386.599, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt43687197.jpg', 'highlights': ['The decorator allows wrapping wide swaths of functions in one fashion without having to rewrite a lot of user code or library code.', "The closure object duality, while not fully explored, is highlighted as a very important concept in Python, hinting at its significance in understanding Python's functionality.", 'The decorator works on any function that takes any arbitrary set of positional and keyword parameters and forwards them on, making it versatile and adaptable.', 'Creating a decorator to run a function n times involves constructing the decorator by adding one more level to the wrapper function, demonstrating the concept of higher order decorators.', "Decorators are considered one of the least interesting features compared to other functions, with the next feature to be explored being generators, emphasizing the depth and breadth of Python's capabilities.", 'The fundamental difference between top-level syntax and object methods The speaker discusses the distinction between top-level syntax and object methods, highlighting the difference between the function and class and their implementation.', 'Efficient processing and object model The importance of efficient processing is emphasized, as the speaker rewrites a function as a class, showcasing the significance of iterating through elements one by one and processing them efficiently.', 'Implications of eager computation on time and memory The chapter explores the implications of eager computation on time and memory, emphasizing the wastefulness of eagerly giving the entire result set, leading to prolonged waiting times and excessive memory usage.', 'Python top-level syntax or functions have corresponding underscore methods that can be implemented, such as iter and next, allowing a class to be iterated over.', 'The iter and next methods can be added to a class in Python to enable iteration, with the iter method returning self and the next method computing and returning values one at a time.', 'The generator syntax provides a simpler way to write functions that can be iterated over, maintaining internal state and yielding values as they are requested by the user.', 'Generators allow interleaving of user and library code while enforcing sequencing, providing a critical mental model for API design. Generators enable interleaving user and library code while ensuring a fixed sequencing, which is crucial for API design.', 'Traditional APIs lack control over code sequencing, leading to potential errors if methods are not executed in the correct order. Conventional APIs have limitations in controlling code sequencing, increasing the risk of errors if methods are not executed in the specified order.', 'Generators act as coroutines, ensuring the execution order of methods and preventing the out-of-sequence call of functions. Generators serve as coroutines, controlling the order of method execution and preventing out-of-sequence function calls.']}, {'end': 5956.673, 'segs': [{'end': 5165.701, 'src': 'embed', 'start': 5137.003, 'weight': 1, 'content': [{'end': 5141.246, 'text': 'This is especially true on Windows, because on Linux, file locks are a little bit less aggressive.', 'start': 5137.003, 'duration': 4.243}, {'end': 5144.028, 'text': "On Windows, if you don't close the file, you might not be able to delete it later.", 'start': 5141.286, 'duration': 2.742}, {'end': 5152.589, 'text': "This is especially true if perhaps this file is backed by some storage where it's not necessarily automatically flushed, if there's some I.O.", 'start': 5145.063, 'duration': 7.526}, {'end': 5156.393, 'text': 'buffering, because, definitely, if you open the file and you write to it,', 'start': 5152.63, 'duration': 3.763}, {'end': 5162.418, 'text': 'you want to make sure those are flushed to disk in case the program terminates at some point with unflushed I.O.', 'start': 5156.393, 'duration': 6.025}, {'end': 5165.701, 'text': 'buffers, you might lose things that you intended to be written to disk.', 'start': 5162.458, 'duration': 3.243}], 'summary': 'On windows, not closing files can prevent deletion; ensure flushing for data integrity.', 'duration': 28.698, 'max_score': 5137.003, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt45137003.jpg'}, {'end': 5210.107, 'src': 'embed', 'start': 5178.115, 'weight': 3, 'content': [{'end': 5179.356, 'text': 'Let me show you an example of that.', 'start': 5178.115, 'duration': 1.241}, {'end': 5185.598, 'text': 'It goes beyond files, but it can go even into things like SQLite databases.', 'start': 5180.876, 'duration': 4.722}, {'end': 5192.06, 'text': 'In SQLite, we have these file-backed databases.', 'start': 5188.559, 'duration': 3.501}, {'end': 5195.101, 'text': 'The connect method is actually a context manager itself.', 'start': 5192.8, 'duration': 2.301}, {'end': 5210.107, 'text': 'So here, I connected some database, I have some cursor on that database, and let me just do this.', 'start': 5204.366, 'duration': 5.741}], 'summary': 'Demonstrating file-backed and sqlite databases with context manager.', 'duration': 31.992, 'max_score': 5178.115, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt45178115.jpg'}, {'end': 5934.069, 'src': 'heatmap', 'start': 5823.87, 'weight': 0, 'content': [{'end': 5828.851, 'text': 'What is it? What will we do here? Why would we not write this? Because we have a simpler syntax.', 'start': 5823.87, 'duration': 4.981}, {'end': 5833.526, 'text': 'What could we write easier here? Anybody? Decorator.', 'start': 5828.871, 'duration': 4.655}, {'end': 5841.452, 'text': "Decorator So you can see it works without the decorator, but we'd probably just write this like that.", 'start': 5834.067, 'duration': 7.385}, {'end': 5845.015, 'text': 'Right? Oops.', 'start': 5842.653, 'duration': 2.362}, {'end': 5846.976, 'text': 'It still works.', 'start': 5846.436, 'duration': 0.54}, {'end': 5850.839, 'text': "Well, it turns out all this garbage up here, we don't have to write.", 'start': 5847.436, 'duration': 3.403}, {'end': 5851.779, 'text': "It's already been written for us.", 'start': 5850.859, 'duration': 0.92}, {'end': 5853.941, 'text': "It's in a library called contextlib.", 'start': 5852.5, 'duration': 1.441}, {'end': 5864.759, 'text': "And it's just a decorator that turns a generator into a context manager.", 'start': 5858.815, 'duration': 5.944}, {'end': 5870.763, 'text': 'And the only things that we need to make this work completely is that.', 'start': 5865.459, 'duration': 5.304}, {'end': 5874.546, 'text': 'Here in this example, I want to show you something.', 'start': 5872.384, 'duration': 2.162}, {'end': 5880.149, 'text': 'This is an example that combines three core features of Python together.', 'start': 5875.926, 'duration': 4.223}, {'end': 5883.972, 'text': 'Generators, context managers, and decorators.', 'start': 5881.09, 'duration': 2.882}, {'end': 5889.917, 'text': "It doesn't, requiring that you know a little bit of the details of how each of these work.", 'start': 5885.515, 'duration': 4.402}, {'end': 5901.122, 'text': 'But fundamentally what we can see is what we have here is three features with very clear conceptual meaning orthogonal conceptual meaning,', 'start': 5890.597, 'duration': 10.525}, {'end': 5904.064, 'text': 'where each of those pieces of conceptual meaning kind of fit together.', 'start': 5901.122, 'duration': 2.942}, {'end': 5911.067, 'text': 'A context manager is merely some piece of code that pairs setup and teardown actions,', 'start': 5904.824, 'duration': 6.243}, {'end': 5914.369, 'text': 'so that the teardown action always occurs if the setup action occurred.', 'start': 5911.067, 'duration': 3.302}, {'end': 5922.847, 'text': 'A generator is merely some form of syntax that allows us to do things like enforce sequencing and interleaving.', 'start': 5915.245, 'duration': 7.602}, {'end': 5930.248, 'text': 'Notice the context manager requires interleaving because the setup is interleaved with the actual action you do in the block.', 'start': 5923.747, 'duration': 6.501}, {'end': 5934.069, 'text': 'You do the setup, then the action in the block, then the teardown at the end.', 'start': 5930.668, 'duration': 3.401}], 'summary': 'Python contextlib library simplifies code with generators, context managers, and decorators.', 'duration': 75.254, 'max_score': 5823.87, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt45823870.jpg'}], 'start': 5075.396, 'title': 'Understanding context managers in python', 'summary': 'Introduces the concept of context managers, providing examples in c++, java, and python, emphasizing the importance of combining setup and teardown actions, particularly in scenarios like file handling. it also explains the implementation and usage of context managers in python, demonstrating their functionality through the creation of a context manager for database operations and highlighting the integration of generators and decorators.', 'chapters': [{'end': 5177.395, 'start': 5075.396, 'title': 'Understanding context managers', 'summary': 'Introduces the concept of context managers, providing examples in c++, java, and python, emphasizing the importance of combining setup and teardown actions, particularly in scenarios like file handling.', 'duration': 101.999, 'highlights': ['Context managers are a common metaphor in programming languages like C++, Java, and Python, used to combine setup and teardown actions, as exemplified by file handling in Python.', 'The necessity of combining setup and teardown actions is emphasized by scenarios like file handling on Windows, where failure to close a file could prevent its deletion and lead to data loss due to unflushed I.O. buffers.']}, {'end': 5956.673, 'start': 5178.115, 'title': 'Understanding context managers in python', 'summary': 'Explains the implementation and usage of context managers in python, demonstrating their functionality through the creation of a context manager for database operations and highlighting the integration of generators and decorators.', 'duration': 778.558, 'highlights': ['Context managers provide a way to pair setup and teardown actions, ensuring that the teardown always occurs if the setup has occurred. Context managers are used to ensure the execution of specific actions before and after a block of code, providing a guarantee that the teardown action occurs if the setup action has taken place.', 'The chapter demonstrates the creation of a context manager for database operations, showcasing the usage of enter and exit methods for setup and teardown actions. The transcript provides a practical example of creating a context manager for database operations, illustrating the implementation of enter and exit methods to execute setup and teardown actions, such as creating and dropping a table.', 'The integration of generators and decorators is highlighted, showcasing how generators enforce sequencing and interleaving, aligning with the requirements of context managers. The chapter emphasizes the integration of generators and decorators to adapt the generator functionality to the data model of context managers, demonstrating how generators enforce sequencing and interleaving, aligning with the requirements of context managers.']}], 'duration': 881.277, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt45075396.jpg', 'highlights': ['Context managers combine setup and teardown actions in C++, Java, and Python.', 'Failure to close a file in scenarios like file handling on Windows can lead to data loss.', 'Context managers ensure teardown always occurs if the setup has occurred.', 'The chapter demonstrates creating a context manager for database operations.', 'Generators and decorators are integrated to adapt the generator functionality to the data model of context managers.']}, {'end': 6845.916, 'segs': [{'end': 6022.19, 'src': 'embed', 'start': 5995.673, 'weight': 5, 'content': [{'end': 6004.359, 'text': 'And how some of these core pieces of Python fit together to write what you might consider to be more nearly expert level code.', 'start': 5995.673, 'duration': 8.686}, {'end': 6011.485, 'text': 'What I can tell you is that in Python, expert level code is not code that uses every single feature.', 'start': 6005.961, 'duration': 5.524}, {'end': 6016.108, 'text': "It's in fact not code that even uses that many features of Python.", 'start': 6012.406, 'duration': 3.702}, {'end': 6022.19, 'text': "It's code that has a certain clarity to where and when a feature should be used.", 'start': 6016.768, 'duration': 5.422}], 'summary': 'Expert level python code focuses on clarity over using every feature.', 'duration': 26.517, 'max_score': 5995.673, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt45995673.jpg'}, {'end': 6158.994, 'src': 'embed', 'start': 6129.62, 'weight': 1, 'content': [{'end': 6134.023, 'text': 'So what I can tell you as the real lessons from this session are as follows.', 'start': 6129.62, 'duration': 4.403}, {'end': 6137.085, 'text': 'Python is a language orientated around protocols.', 'start': 6134.783, 'duration': 2.302}, {'end': 6143.447, 'text': "There's some behavior, some syntax, some bytecode or some top-level function,", 'start': 6137.765, 'duration': 5.682}, {'end': 6148.99, 'text': "and there's a way for you to tell Python how to implement that on an arbitrary object via underscore methods.", 'start': 6143.447, 'duration': 5.543}, {'end': 6153.372, 'text': "That exact correspondence is usually guessable, but if you can't guess it,", 'start': 6149.55, 'duration': 3.822}, {'end': 6158.994, 'text': "Google Python data model and you'll find all the different methods and all of the caveats of their use.", 'start': 6153.372, 'duration': 5.622}], 'summary': "Python is protocol-oriented with underscore methods. google 'python data model' for details.", 'duration': 29.374, 'max_score': 6129.62, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt46129620.jpg'}, {'end': 6376.528, 'src': 'embed', 'start': 6342.193, 'weight': 0, 'content': [{'end': 6347.317, 'text': 'Generators are merely a way to take a single computation that would otherwise run eagerly.', 'start': 6342.193, 'duration': 5.124}, {'end': 6366.347, 'text': 'from the injection of its parameters to the final computation and interleave it with other code by adding yield points where you can yield the intermediate result values or one small piece of the computation and also yield control back to the caller.', 'start': 6348.217, 'duration': 18.13}, {'end': 6376.528, 'text': 'In that vein, you can think of a generator as being a way to take one long piece of one long computation and break it up in small parts,', 'start': 6367.884, 'duration': 8.644}], 'summary': 'Generators break up a computation into small parts, yielding intermediate results and control back to the caller.', 'duration': 34.335, 'max_score': 6342.193, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt46342193.jpg'}, {'end': 6431.462, 'src': 'embed', 'start': 6407.566, 'weight': 2, 'content': [{'end': 6413.73, 'text': 'because the generator can just yield the values back to you and you can choose which of those return values you want to keep,', 'start': 6407.566, 'duration': 6.164}, {'end': 6414.631, 'text': 'which of them you want to throw away.', 'start': 6413.73, 'duration': 0.901}, {'end': 6425.897, 'text': 'Context. managers are merely some structure for allowing you to tie two actions together a setup action and a teardown action and make sure that they always happen in concordance with each other.', 'start': 6415.97, 'duration': 9.927}, {'end': 6431.462, 'text': 'If the setup action occurs, make sure that teardown action occurs even if some error happens in the middle.', 'start': 6426.438, 'duration': 5.024}], 'summary': 'Generators yield values for selection, while managers ensure paired actions always occur together.', 'duration': 23.896, 'max_score': 6407.566, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt46407566.jpg'}, {'end': 6607.13, 'src': 'embed', 'start': 6577.945, 'weight': 3, 'content': [{'end': 6594.697, 'text': 'And so where you see generators used as part of this broader idea of concurrency in Python is that the generator mechanism and its syntax have been further refined in Python 3.6 to this asynchronous coroutine syntax.', 'start': 6577.945, 'duration': 16.752}, {'end': 6607.13, 'text': 'There are many reasons why strictly simultaneous running Python code is something that has been avoided for a very long time in Python.', 'start': 6596.459, 'duration': 10.671}], 'summary': 'Python 3.6 refined generator for asynchronous coroutine syntax.', 'duration': 29.185, 'max_score': 6577.945, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt46577945.jpg'}, {'end': 6708.936, 'src': 'embed', 'start': 6681.873, 'weight': 4, 'content': [{'end': 6685.794, 'text': 'The problem is runtime checks require you to have the code deployed in a runtime environment.', 'start': 6681.873, 'duration': 3.921}, {'end': 6689.836, 'text': "You'll never know the problem until you hit that exact code path.", 'start': 6686.855, 'duration': 2.981}, {'end': 6698.565, 'text': 'The whole point of this is can we, any sooner than when it hits that code path in a deploy environment, catch the error?', 'start': 6690.836, 'duration': 7.729}, {'end': 6700.888, 'text': 'Any kind of run?', 'start': 6699.826, 'duration': 1.062}, {'end': 6703.33, 'text': "because Python doesn't have a very strong compiler.", 'start': 6700.888, 'duration': 2.442}, {'end': 6705.613, 'text': 'it has a very small, very.', 'start': 6703.33, 'duration': 2.283}, {'end': 6706.854, 'text': "that compiler doesn't really do a lot.", 'start': 6705.613, 'duration': 1.241}, {'end': 6708.936, 'text': "it's going to be very difficult.", 'start': 6707.955, 'duration': 0.981}], 'summary': "Runtime checks reveal errors only at deployment, due to python's weak compiler.", 'duration': 27.063, 'max_score': 6681.873, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt46681873.jpg'}, {'end': 6845.916, 'src': 'heatmap', 'start': 6778.237, 'weight': 7, 'content': [{'end': 6781.558, 'text': 'A NIT subclass will operate in the same fashion as the metaclass.', 'start': 6778.237, 'duration': 3.321}, {'end': 6787.4, 'text': "It'll merely just another place that you can hook into the initialization of a subclass.", 'start': 6782.138, 'duration': 5.262}, {'end': 6789.441, 'text': 'You have to look into the details.', 'start': 6788.44, 'duration': 1.001}, {'end': 6791.381, 'text': 'I thought it took different arguments than it does.', 'start': 6789.901, 'duration': 1.48}, {'end': 6798.804, 'text': "You'll have to look into the details to see what arguments it takes and how you actually use it for this purpose.", 'start': 6792.142, 'duration': 6.662}, {'end': 6803.597, 'text': "There's a lot of these details of these features.", 'start': 6800.453, 'duration': 3.144}, {'end': 6810.924, 'text': "Hopefully you're not somebody who's constantly using them, and unless you're constantly using them, the details are things that are easy to forget.", 'start': 6804.037, 'duration': 6.887}, {'end': 6817.439, 'text': 'If you know where to look or if you know what to look for, those are details that you can very quickly pick up.', 'start': 6813.297, 'duration': 4.142}, {'end': 6822.761, 'text': 'And frankly, and its subclass has only been around since 3.6, a lot of these details do change over time.', 'start': 6817.579, 'duration': 5.182}, {'end': 6828.103, 'text': 'But the core models, the core mental models have not changed since these features were first introduced.', 'start': 6823.161, 'duration': 4.942}, {'end': 6833.845, 'text': 'Even the extension of generators for coroutines and for asynchronous programming.', 'start': 6828.683, 'duration': 5.162}, {'end': 6839.548, 'text': "the core mental models behind it haven't really changed since they were first introduced in Python 2.6, 2 whatever.", 'start': 6833.845, 'duration': 5.703}, {'end': 6845.274, 'text': 'Any last questions? Okay, well I hope you enjoyed the session.', 'start': 6841.549, 'duration': 3.725}, {'end': 6845.916, 'text': 'Thank you very much.', 'start': 6845.335, 'duration': 0.581}], 'summary': 'Nit subclass operates like metaclass, details evolve over time, core mental models remain unchanged since python 2.6.', 'duration': 67.679, 'max_score': 6778.237, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt46778237.jpg'}, {'end': 6845.916, 'src': 'embed', 'start': 6833.845, 'weight': 6, 'content': [{'end': 6839.548, 'text': "the core mental models behind it haven't really changed since they were first introduced in Python 2.6, 2 whatever.", 'start': 6833.845, 'duration': 5.703}, {'end': 6845.274, 'text': 'Any last questions? Okay, well I hope you enjoyed the session.', 'start': 6841.549, 'duration': 3.725}, {'end': 6845.916, 'text': 'Thank you very much.', 'start': 6845.335, 'duration': 0.581}], 'summary': 'Python mental models remain unchanged since python 2.6 introduction.', 'duration': 12.071, 'max_score': 6833.845, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt46833845.jpg'}], 'start': 5958.315, 'title': "Python's core features and design", 'summary': "Explores python's core features such as decorators, meta classes, generators, and context managers, highlighting the importance of conceptual understanding and practical application over syntax knowledge. it also emphasizes understanding core concepts and mental models behind python features and discusses preferred approaches for concurrency and runtime checks.", 'chapters': [{'end': 6447.619, 'start': 5958.315, 'title': "Python's core features and design", 'summary': 'Explores the core features of python, including decorators, meta classes, generators, and context managers, emphasizing the importance of conceptual understanding and practical application rather than mere syntax knowledge.', 'duration': 489.304, 'highlights': ['Python expert level code is characterized by a certain clarity in feature usage rather than the use of every single feature. Expert level Python code prioritizes clarity in feature usage over the utilization of every feature.', "Python's focus on protocols enables the implementation of behavior, syntax, and bytecode on arbitrary objects via underscore methods, with the correspondence usually being guessable. Python's protocol-based approach allows the implementation of behavior, syntax, and bytecode on arbitrary objects through underscore methods, with the correspondence typically being guessable.", 'Generators allow the interleaving of a single computation with other code by adding yield points, providing greater control over computation and memory usage. Generators enable the interleaving of a single computation with other code through yield points, offering enhanced control over computation and memory usage.', 'Context managers facilitate the coordination of setup and teardown actions, ensuring their concordance, even in the event of errors. Context managers enable the coordination of setup and teardown actions, ensuring their concordance, even in the presence of errors.']}, {'end': 6845.916, 'start': 6448.76, 'title': 'Python features and core concepts', 'summary': 'Emphasizes the importance of understanding core concepts and mental models behind python features, highlighting the significance of remembering their purpose over syntax details, and discusses the limitations and preferred approaches for concurrency and runtime checks in python.', 'duration': 397.156, 'highlights': ['The core meaning behind Python features will guide towards writing expert level Python code far better than memorizing just a bunch of features ever will.', 'The generator mechanism and its syntax have been further refined in Python 3.6 to asynchronous coroutine syntax, addressing the limitations of the global interpreter lock and providing a preferred approach for concurrency in Python.', 'Runtime checks in Python can be performed at module import time to catch errors before hitting the runtime environment, allowing for early identification and resolution of potential issues.', 'Understanding the core mental models behind Python features remains crucial, as the core models and mental models behind Python features have not changed since their introduction, despite the evolving details and syntax over time.', 'The init subclass is a runtime check and operates in the same fashion as the metaclass, providing a hook into the initialization of a subclass.']}], 'duration': 887.601, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/cKPlPJyQrt4/pics/cKPlPJyQrt45958315.jpg', 'highlights': ['Generators enable the interleaving of a single computation with other code through yield points, offering enhanced control over computation and memory usage.', "Python's protocol-based approach allows the implementation of behavior, syntax, and bytecode on arbitrary objects through underscore methods, with the correspondence typically being guessable.", 'Context managers enable the coordination of setup and teardown actions, ensuring their concordance, even in the presence of errors.', 'The generator mechanism and its syntax have been further refined in Python 3.6 to asynchronous coroutine syntax, addressing the limitations of the global interpreter lock and providing a preferred approach for concurrency in Python.', 'Runtime checks in Python can be performed at module import time to catch errors before hitting the runtime environment, allowing for early identification and resolution of potential issues.', 'The core meaning behind Python features will guide towards writing expert level Python code far better than memorizing just a bunch of features ever will.', 'Understanding the core mental models behind Python features remains crucial, as the core models and mental models behind Python features have not changed since their introduction, despite the evolving details and syntax over time.', 'The init subclass is a runtime check and operates in the same fashion as the metaclass, providing a hook into the initialization of a subclass.', 'Python expert level code is characterized by a certain clarity in feature usage rather than the use of every single feature. Expert level Python code prioritizes clarity in feature usage over the utilization of every feature.']}], 'highlights': ['The speaker has extensive experience in the field, having attended approximately 27th or 28th PyData conferences and given around 50 PyData talks in the last four years.', 'The speaker emphasizes the importance of understanding the core mental models for Python features over memorizing syntax and documentation.', 'The chapter emphasizes the significance of understanding metaclasses, decorators, generators, and context managers as powerful mental models for Python expertise.', 'Python code runs linearly from top to bottom, and almost every statement is executable runtime code, unlike C++ or Java, making Python a much simpler language.', "The 'new' method of meta classes intercepts construction of derived types and performs checks.", 'Python decorators simplify adding functionality to existing functions without altering user code.', 'The decorator allows wrapping wide swaths of functions in one fashion without having to rewrite a lot of user code or library code.', 'Python decorators wrap functions with behavior before and after execution, providing an efficient way to add extra functionality.', 'Generators allow interleaving of user and library code while enforcing sequencing, providing a critical mental model for API design.', 'Context managers combine setup and teardown actions in C++, Java, and Python.', 'Generators enable the interleaving of a single computation with other code through yield points, offering enhanced control over computation and memory usage.', "Python's protocol-based approach allows the implementation of behavior, syntax, and bytecode on arbitrary objects through underscore methods, with the correspondence typically being guessable.", 'Understanding the core mental models behind Python features remains crucial, as the core models and mental models behind Python features have not changed since their introduction, despite the evolving details and syntax over time.', 'Python expert level code is characterized by a certain clarity in feature usage rather than the use of every single feature. Expert level Python code prioritizes clarity in feature usage over the utilization of every feature.']}