Just use a local variable for obj or c. It looks like you are trying to use Visual Basic's "with" statement. Python's is closer to C#'s "using".
http://www.python.org/dev/peps/pep-0343/ Phillip B Oldham wrote: > Are there plans to enable use of the python `with` statement? > > For example, it would be useful to be able to do something like the > following (server implementation): > > with MyThriftObject.containedObject as obj: > myvariable = obj.foo > # do something here > > or: > > obj = MyThriftObject() > obj.containedObjects = [] > for my_dict in my_list_of_dicts: > with ContainedObject() as c: > # map my_dict to c here > obj.containedObjects.append(c) > > Currently python throws errors such as: > AttributeError: 'MyThriftObject' object has no attribute '__exit__' >
