From the course: Advanced Python: Build Hands-On Projects with Design Patterns (2023)
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
Solution: Working with a legacy system - Python Tutorial
From the course: 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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.