课程: Advanced Python: Build Hands-On Projects with Design Patterns (2023)
免费学习该课程!
今天就开通帐号,24,700 门业界名师课程任您挑!
Solution: Working with a legacy system - Python教程
课程: Advanced Python: Build Hands-On Projects with Design Patterns (2023)
Solution: Working with a legacy system
- [Instructor] How was your coding? Was it more challenging than you thought? We want to process XML. Therefore, we need to invoke the process method when we identify it as an XML handler. There are many ways to do it, but I can use a for loop to iterate through the objects list until I find the XML handler. Let's first define a temporary variable called temp. Let's set it to None for now. Let's create a for loop. Type for space obj in objects, colon. Press Enter. Type if obj.name is equal to the string XML. Make sure these are capital XML, because this is going to be case sensitive. Colon. This is exactly when we want to invoke the process_XML method. That's why I type temp space assignment, obj.process. Please note that I'm using the generic method name process. Finally, I return the result of XML processing. Type return temp. That's all you need. Not too bad, right? Let's test the code by clicking on Test…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。