contrived-example

Nested try statements in python?

Is there a nicer way of doing the following: try: a.method1() except AttributeError: try: a.method2() except AttributeError: try: a.method3() except AttributeError: raise It looks pretty nasty and I'd rather not do: if hasattr(a, 'method1'): a.method1() else if hasattr(a...

Performance Considerations Using Multiple Layers of Generators in Python?

Are there any performance considerations for using a lot of generators chained together, as opposed to just a single generator. For example: def A(self, items): for item in self.AB(items): if object.A(): yield item def AB(self, items): for object in self.ABC(objects): if object.A() or object.B(): ...

How to correctly allocate memory for a structure in a function to return its value for later use and how to cast a structure into a pointer?

I'm currently self-studying C for mastering an university project. In that project we have several signatures given that we need to implement for solving our task. After several hours of trying to make some progress, I must admit that I'm totally confused about the return types of functions. I will show you some code: This is a structur...