thrift-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Reiss <dre...@facebook.com>
Subject Re: [Python] enabling the `with` statement?
Date Thu, 03 Sep 2009 16:17:55 GMT
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__'
> 

Mime
View raw message